UnmanagedDllResolveHelper 1.1.0

dotnet add package UnmanagedDllResolveHelper --version 1.1.0
                    
NuGet\Install-Package UnmanagedDllResolveHelper -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UnmanagedDllResolveHelper" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UnmanagedDllResolveHelper" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="UnmanagedDllResolveHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UnmanagedDllResolveHelper --version 1.1.0
                    
#r "nuget: UnmanagedDllResolveHelper, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UnmanagedDllResolveHelper@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UnmanagedDllResolveHelper&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=UnmanagedDllResolveHelper&version=1.1.0
                    
Install as a Cake Tool

UnmanagedDllResolveHelper

UnmanagedDllResolveHelper is a .NET helper library for resolving unmanaged (native) library dependencies at runtime, based on the location of the calling native library.
This is especially useful for self-contained native plugins or AOT scenarios where dependent libraries are placed alongside the main native library.

Features

  • Resolves dependent native libraries from the same directory as the calling library
  • Supports Windows, Linux, and macOS
  • No configuration or search path setup required
  • Simple integration with AssemblyLoadContext

How to Use

1. Add Reference

Add a reference to the UnmanagedDllResolveHelper project or NuGet package in your native library project.

2. Register the Resolver

In your native library's static constructor, register the resolver to AssemblyLoadContext.Default.ResolvingUnmanagedDll:

using System.Runtime.Loader;

static Class1()
{
    AssemblyLoadContext.Default.ResolvingUnmanagedDll += UnmanagedDllResolveHelper.UnmanagedDllCurrentLibraryLocationResolver.ResolveUnmanagedDll;
}

3. Use P/Invoke as Usual

Declare your P/Invoke as usual. For example:

[DllImport("SampleNativeLibraryDependency", EntryPoint = "Sum42", CallingConvention = CallingConvention.StdCall)]
public static extern int Sum42(int a);

4. Build and Place Native Libraries

Build your native libraries and place any dependencies in the same directory as the main native library.
For example, if your main library is SampleNativeLibraryWithLoader.dll and it depends on SampleNativeLibraryDependency.dll, place both in the same output folder.

5. Example

public static class Class1
{
    static Class1()
    {
        AssemblyLoadContext.Default.ResolvingUnmanagedDll += UnmanagedDllResolveHelper.UnmanagedDllCurrentLibraryLocationResolver.ResolveUnmanagedDll;
    }

    [DllImport("SampleNativeLibraryDependency", EntryPoint = "Sum42", CallingConvention = CallingConvention.StdCall)]
    public static extern int Sum42(int a);

    [UnmanagedCallersOnly(EntryPoint = "Run", CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvStdcall) })]
    public static int Run(int a)
    {
        return Sum42(a);
    }
}

Testing

See UnmanagedDllResolveHelper.Tests/UnitTest1.cs for a dynamic loading example using NativeLibrary.Load and function pointer binding.

Supported Platforms

  • Windows (.dll)
  • Linux (.so)
  • macOS (.dylib)

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 159 7/17/2025
1.0.0 141 7/16/2025