-
Notifications
You must be signed in to change notification settings - Fork 10
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
Comments
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); |
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 If I execute the following in the Immediate Window, I get the 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. |
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. |
The difference between the 2 sets of code are that in my code, the |
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. |
Thank you, I appreciate it. Thank you also for sharing a great tool. |
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))
The text was updated successfully, but these errors were encountered: