Call .NET 8.0 DLL from Clarion 10 application


I have been using a .NET Framework DLL in our Clarion application for many years without issues. We were recently forced to upgrade our library to .NET 8.0 due to a dependency update. Since the update, the Clarion app instantly crashes instantly when calling any of the exported DLL functions.

To simplify testing and remove variables, I have created a test app in Clarion 10 (using the Win32 EXE template) and a test library using the “CLR Class Library (.NET)” template in Visual Studio 2022.

I have tested linking to the library both statically (using both the built-in LibMaker.exe and LibMakerPlus from and also dynamically using the LoadLibrary() APIs without success. Note that when I create the same library from the “CLR Class Library (.NET Framework)” template in VS, both of the linking methods work without crashing.

Is there some extra configuration that I need to make in the .NET library to be compatible with Clarion?

My current library code looks like the following…

// Net.h
#pragma once

extern "C" __declspec(dllexport) int GetSeven();

// Net.cpp
#include "pch.h"
#include "Net.h"

int GetSeven()
	return 7;

I am compiling in release mode targeting x86.

My Clarion app code looks like the following…

! Main procedure
Main                 PROCEDURE                             ! Declare Procedure

  CODE                                                     ! Begin processed code
		MESSAGE('Done!')  ! This never gets called because Clarion crashes on the previous line

! Global map

I have generated the LIB file using LibMaker.exe (the function shows up correctly in the preview) and added the library in the Solution Explorer.

I have been stuck on this for weeks, so any help would be greatly appreciated!

Thank you,

There’s a Nuget package called Unmanaged Exports that I’ve used for a long time to call . NET methods. There’s a ClarionMag article that covers its use.

Maybe that will help.

I recently had to swap the UnmanagedExport for the DllExport package, because at some point of version of .net, it stopped exporting methods. Also, the DllExport is on github and seems actively supported.


Thank you for the suggestions. I attempted to create a brand new C# Class Library (using .NET 8.0 framework).

The UnmanagedExports package gives the following warning when installed…

Severity	Code	Description	Project	File	Line	Suppression State	Details
Warning	NU1701	Package 'UnmanagedExports 1.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net8.0'. This package may not be fully compatible with your project.

I am struggling with the DllExport package. Do you remember which settings you configured in the GUI that pops up right after installation?

I am not using UnmanagedExports, but the DllExport package.
I found the DllExport.bat somewhere and put that in my project directory.
The most important thing is the x86 setting. I have used different values for namespace, I have had trouble with the one “System.Runtime.Interop.Services”, but not with the ones with projectname.

@Brandon - Seems we’re in the same boat - I’ve been succesfully exporting my DotNet 8 Library using DNNE - I’ve created a fork of it which also generates the necessary files to use the exported methods in a class inside Clarion itself - I also got it working to generate the LIB - so all in all it generates the .CLW, .INC and .LIB needed to consume the library - my fork is far from complete - currently working on a rewrite to make it easier to extend - if interrested though, I can give a small headsup on how to use it - but you’ll have to compile it locally and use a local Nuget Source to use it

1 Like

Also keep a eye out for Native AOT from Microsoft - they are working on support for x86 (there is basic support now it seems) - but when Clarion 12 lands (with x64 support) you can just use Native AOT instead

Just to clarify your roadmap; 64bit support has been discussed but is -not- on the roadmap for Clarion 12 . It is slated for some later version.

Hi Bruce - The graphic on this post seems to state otherwise.

Oh. My mistake. It says “Clarion 2024”.

Will any of us be alive when Clarion 2024 is released? :wink: