Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HelpPageMiddlewareExtensions.GetBinPath() causes The path is not of a legal form. #7

Open
willemsevenster opened this issue Jan 11, 2017 · 6 comments

Comments

@willemsevenster
Copy link

The error is in how the CodeBase value is formatted - it is a Uri rather than a path. The implementation of the GetBinPath() method could perhaps be changed to:
return Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase)?.LocalPath);

or at least to

return Path.GetDirectoryName((Assembly.GetExecutingAssembly().GetName().CodeBase ?? string.Empty).Replace("file:///", string.Empty))

@DalSoft
Copy link
Owner

DalSoft commented Jan 11, 2017

Under what conditions are you getting this exception?

The return already does the replace.

var executingAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? string.Empty;
return executingAssemblyPath.Replace("file:\\", string.Empty);

@willemsevenster
Copy link
Author

I'm running my project in a self-hosted Owin Web Api project using .Net 4.6.2. After investigating further, in my Owin StartUp class, the call to Assembly.GetExecutingAssembly().GetName() returns "file:///D:/Work/tfs/SPQ.MicroScheduler/SPQ.MicroScheduler.Services.Api/bin/Debug/mschedapisvc.EXE".

If I execute the following in the Immediate Window, I get the The path is not of a legal form exception:
Path.GetDirectoryName("file:///D:/Work/tfs/SPQ.MicroScheduler/SPQ.MicroScheduler.Services.Api/bin/Debug/mschedapisvc.EXE")

If I remove the `file:///' bit at the start, it works fine in the Immediate Window.

If I execute the same instruction above in the C# Interactive window, I do not get the error. This does not seem to be an issue with your code, but rather an anomoly/bug in the .Net framework. My fix above does work in all instances.

@DalSoft
Copy link
Owner

DalSoft commented Jan 12, 2017

Sure but doesn't mine:

var executingAssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) ?? string.Empty;
return executingAssemblyPath.Replace("file:\\", string.Empty);

And yours ...

return Path.GetDirectoryName((Assembly.GetExecutingAssembly().GetName().CodeBase ?? string.Empty).Replace("file:///", string.Empty))

Do the same thing or am I missing something? Please feel free to re-open if I am.

@DalSoft DalSoft closed this as completed Jan 12, 2017
@willemsevenster
Copy link
Author

The difference between the 2 sets of code are that in my code, the file:/// is removed from the path before it is being sent to the Path.GetDirectory() method. This seems to overcome the issue in the framework code.

@DalSoft
Copy link
Owner

DalSoft commented Jan 12, 2017

Ok I see what your saying under certain conditions Path.GetDirectory throws before the return. Thank you that makes sense. I'll make the change so that file:// is striped off first.

@DalSoft DalSoft reopened this Jan 12, 2017
@willemsevenster
Copy link
Author

Thank you, I appreciate it. Thank you also for sharing a great tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants