DllImportX 0.0.1

.NET Standard 1.5 .NET Framework 3.5
dotnet add package DllImportX --version 0.0.1
NuGet\Install-Package DllImportX -Version 0.0.1
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="DllImportX" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DllImportX --version 0.0.1
#r "nuget: DllImportX, 0.0.1"
#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.
// Install DllImportX as a Cake Addin
#addin nuget:?package=DllImportX&version=0.0.1

// Install DllImportX as a Cake Tool
#tool nuget:?package=DllImportX&version=0.0.1

DllImportX is an attribute to work around the classic DllImport's limitations.

The .Net platform does not allow to define dynamic values in the attributes assignments to perform environment based unmanaged library linking.

With DllImporX, you can dynamically set the DllImport attribute at runtime changing everyone attributes as necessary!

DllImportX's attribute supports all the classic DllImport parameters. All you need is add the 'X' in the DllImport attribute and build your instance.

How to use

If you have an unmanaged static-link library with this functions:

// sample.h
// Unmanaged C sample functions

void cVoidSample();
int cIntSample(int intParam);
void cOutIntSample(int* outIntParam);
void cRefIntSample(int* refIntParam);
void cAnsiStringSample(const char* str);
void cPtrSample(void* ptr);

You must only define an interface in your project:

// ISample.cs

using System;
using System.Runtime.InteropServices;

namespace DllImportXSample
    public interface ISample
        void cVoidSample();

        int cIntSample(int intParam);

        [DllImportX("Sample.dll", EntryPoint = "cOutIntSample")]
        void OutIntSample(out int outIntParam);

        [DllImportX("Sample.dll", EntryPoint = "cRefIntSample"))]
        void cRefIntSample(ref int refIntParam);

        [DllImportX("Sample.dll", EntryPoint = "cAnsiString"))]
        void AnsiStringSample([In][MarshalAs(UnmanagedType.LPStr)] string str);

        void cPtrSample(IntPtr ptr);

And build your instance!

using System.Runtime.InteropServices;
using DllImportXSample;

// ...
var sampleInstance = DllImportXFactory
    .Build<ISample>(entry => {
        // Change the path to the unmanged static-link library
        // based in the runtime enviroment architeture
        entry.DllName = (IntPtr.Size == 8 ? "x64/" : "x86/") + entry.DllName;

// ready

sampleInstance.AnsiStringSample("Hello world.");

// ...

Bug Reports

If you find any bug, please report them using the GitHub issue tracker.


This software is distributed under the terms of the MIT license.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DllImportX:

Package Downloads

This package is a Neoload Ranorex Plugin. For more information see https://github.com/Neotys-Labs/Ranorex

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.1 3,765 8/23/2017