Passing path with forward-slashes to LoadUnmanagedDllFromPath cause load to fail
See original GitHub issueDescribe the bug
When a native binary in a package is defined in the .nuspec
using forward-slashes, AssemblyLoadContext.LoadUnmanagedDllFromPath()
will fail loading it.
Sample <file>
causing this failure:
Foo.nuspec
<files>
<file src="nativeassets\*.dll" target="runtimes/win-x64/native" />
</files>
To Reproduce Steps to reproduce the behavior:
- Define a NuGet package that include a native binary using the above pattern.
- Load an assembly in an ALC (
new ManagedLoadContext(...)
) that depend on the native binary and execute some code in it, e.g. using P/Invoke.
Expected behavior
The native binary is found and successfully loaded by DotNetCorePlugins
.
Actual behavior The native binary is found, but fail to load.
Screenshots
Additional context
Spent quite some time figuring out what this problem was about, and what especially fooled me was that File.Exist(unmanagedPath)
return true, because that API clearly deal with mixed slashes. Then when you pass the path on to LoadContext.LoadUnmanagedDllFromPath(path)
here, here, here or here, it will raise the above exception.
Considered making a PR, but wasn’t sure in what spot you want to deal with this - SeachForLibrary maybe - or if this even should be reported as a flaw in AssemblyLoadContext.LoadUnmanagedDllFromPath
. If the later, just let me know and I’ll file an issue there instead.
Tested only on
.NET Core SDK (reflecting any global.json):
Version: 2.2.101
Commit: 236713b0b7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.101\
Host (useful for support):
Version: 2.2.0
Commit: 1249f08fed
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
@per-samuelsson thanks for sharing details on your investigation. I’d be happy to add a workaround to this library which normalizes the file path before calling LoadUnmanagedDllFromPath. Feel free to send a PR and I can get an update to nuget.org this week.
Yes, can you please open this on https://github.com/dotnet/coreclr, if it doesn’t exist already?
In the meantime, I’m happy to take a workaround for this that normalizes slashes before calling LoadUnmanagedDllFromPath.