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:

1. Determine the active AssemblyLoadContext. For an unmanaged load library, the active AssemblyLoadContext is the caller of the PInvoke.

2. For the active AssemblyLoadContext, try to find the assembly in priority order by:

3. If the unmanaged library is newly loaded, the AppDomain.AssemblyLoad event is raised.