Error while loading unmanaged dlls
See original GitHub issue“CreateFromPackage” method defined in “NativeLibrary” class sets the native library name as a library’s dll name without extension (https://github.com/natemcmaster/DotNetCorePlugins/blob/91b44684f5f696cc7c51d4eae1081e339ff77a15/src/Plugins/LibraryModel/NativeLibrary.cs#L56).
This name is used by “AssemblyLoadContextBuilder” in “AddNativeLibrary” method as a key for a “_nativeLibraries” dictionary (https://github.com/natemcmaster/DotNetCorePlugins/blob/91b44684f5f696cc7c51d4eae1081e339ff77a15/src/Plugins/Loader/AssemblyLoadContextBuilder.cs#L158) wich later passed to the “ManagedLoadContext” constructor.
“ManagedLoadContext” class defines “LoadUnmanagedDll(string unmanagedDllName)” method to proccess unmanaged dll requests (https://github.com/natemcmaster/DotNetCorePlugins/blob/91b44684f5f696cc7c51d4eae1081e339ff77a15/src/Plugins/Loader/ManagedLoadContext.cs#L113). This method trying to get “NativeLibrary” instance from “_nativeLibraries” dictionary, using platform related prefixes + “unmanagedDllName”.
“unmanagedDllName” argument of “LoadUnmanagedDll” may contain both library name and library file path (absolute or relative). In second case (for example, https://github.com/dotnet/corefx/blob/8f7b490ca874ee2a9f11f0163412f7c95811298b/src/System.Data.SqlClient/src/Interop/SNINativeMethodWrapper.Windows.cs#L183
private const string SNI = "sni.dll";
...
[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIAddProviderWrapper")]
internal static extern uint SNIAddProvider(SNIHandle pConn, ProviderEnum ProvNum, [In] ref uint pInfo);
) “LoadUnmanagedDll” method will fail.
It seems that trimming path and extensions from “PlatformInformation.NativeLibraryExtensions” in “unmanagedDllName” is appropriate here. Or better “Path.GetFileNameWithoutExtension” call as it works in “NativeLibrary.CreateFromPackage”.
Hope my description is understoodable.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
@maxacoustic give this build of the package a try and let me know if it you still have issues.
https://www.myget.org/feed/natemcmaster/package/nuget/McMaster.NETCore.Plugins/0.2.2-rtm.40
Have you tried
dotnet publish
instead ofdotnet build
?