HDF.PInvoke icon indicating copy to clipboard operation
HDF.PInvoke copied to clipboard

Invalid dll-path when there is a '#' in the path

Open JanWosnitza opened this issue 8 years ago • 2 comments

In NativeDependencies.GetAssemblyName() the binary search path based on this code:

string myPath = new Uri(System.Reflection.Assembly
    .GetExecutingAssembly().CodeBase).AbsolutePath;
myPath = Uri.UnescapeDataString(myPath);
return myPath;

which transforms a path c:\Dir\Sub#Dir\HDF.PInvoke.dll into c:\Dir\Sub.

A fix could look like this:

var myPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
return Path.GetDirectoryName( myPath );

which transforms a path c:\Dir\Sub#Dir\HDF.PInvoke.dll into c:\Dir\Sub#Dir.

JanWosnitza avatar Jan 19 '17 15:01 JanWosnitza

I would say this is a this is a bug in Assembly.CodeBase, because '#' should be escaped as '%23'.

JanWosnitza avatar Jan 19 '17 16:01 JanWosnitza

or new Uri(...Assembly.EscapedCodeBase).AbsolutePath would do the job too.

Replacing Uri.AbsolutePath& Uri.UnescapeDataString() with Uri.LocalPath might also be an option?

JanWosnitza avatar Jan 19 '17 16:01 JanWosnitza