Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Unmanaged libraries are located and loaded with an algorithm involving various stages.
The following algorithm describes how native libraries are loaded through PInvoke.
PInvoke load library algorithm
PInvoke uses the following algorithm when attempting to load an unmanaged assembly:
Determine the
activeAssemblyLoadContext. For an unmanaged load library, theactiveAssemblyLoadContext is the one with the assembly that defines thePInvoke.For the
activeAssemblyLoadContext, try to find the assembly in priority order by:Checking its cache.
Calling the current System.Runtime.InteropServices.DllImportResolver delegate set by the NativeLibrary.SetDllImportResolver(Assembly, DllImportResolver) function.
Calling the AssemblyLoadContext.LoadUnmanagedDll function on the
activeAssemblyLoadContext.Checking the AppDomain instance's cache and running the Unmanaged (native) library probing logic.
Raising the AssemblyLoadContext.ResolvingUnmanagedDll event for the
activeAssemblyLoadContext.