question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
natemcmastercommented, Jan 15, 2019

@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

1reaction
dferretticommented, Jan 11, 2019

Have you tried dotnet publish instead of dotnet build?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unmanaged DLLs fail to load on ASP.NET server
One easy solution is to put the unmanaged dlls in a directory that is in the system path (type "path" at the command...
Read more >
How to use the concept of activation context in .net to load ...
In my application, I have to load an unmanaged dll c.dll by another managed dll b.dll , which is loaded by a.dll ,...
Read more >
Unmanaged DLL not being found
Looks like you are in "dll hell". Your only friend is the good old Dependency Walker. Often this error is a syndrom that...
Read more >
Thread: [RESOLVED] unable to load unmanaged dll
I have code to call a DLL that I wrote in C (see end of message). This code has worked fine for months....
Read more >
Unhandled exception - couldn't load Unmanaged.dll
The web client works fine, but when starting the Windows client, I get the following message: "unhandled exception has occurred in a component...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found