Call .NET 8.0 DLL from Clarion 10 application

Thank you @Brandon , it really helped.
I would add that you need to copy both DLLs (TestDnneCNE.dll and TestDnneC.dll) to Clarion directory, an must have TestDnneC.runtimeconfig.json with:

{
  "runtimeOptions": {
    "tfm": "net8.0",
    "rollForward": "LatestMinor",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "8.0.0"
    },
    "configProperties": {
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

Now I just have to make it pass and return a string parameter.

I would advice you to switch to NativeAoT now it supports 32-bit in Dotnet 9 - as you’ll only need the single DLL, you don’t need the runtimeconfig.json anymore

@uriah18 - if you need help, you may PM/DM me - I’ve been doing this for some time and may be able to help you - I recently got it working so I can even pass a GROUP from Clarion to DotNet

@ThaDaSoft
Hi! I’m new to Clarion and want to create a DLL for Clarion using .NET 9. What do I have to do? Can you help me and show an example? Thanks!

@fabian488 - please DM me about this, I am happy to help you get started

Thank you. I did it like you said, using .net9, which is now out of RC. So far everything looks good. I had to jump on another project in the meantime and now I’m back on this. @fabian488 if you need help, ask.

If you need help @uriah18 - you can DM me like @fabian488 did

Hi @ThaDaSoft

I was wondering when you have some time if you could perhaps create a post on the hub that explains how to use AOT with clarion.

I’m sure it would be appreciate by many developers, and will save you having to respond to personal DM’s each time.

Kind regards

Mark

Most of the time it’s project specific - but one can start with the following:
See below for the basics regarding NativeAoT:

Most importantly, you have to publish for Windows x86 (32-bit) - I do this by using

dotnet publish -r win-x86 -c Release

And following the following to export the functions:

It’s all about using

But the first step would be, to make your Library compilable with NativeAoT in x86.

After that it’s project specific, hence why I asked for the DM as it’s easier to help that way

Hi Dylan,

Thank you for the information.

I had a play around yesterday and managed to get it working. I found that I needed to modify my Visual Studio 2022 installation to include the Desktop Development with C++ tools because the Win32 AOT compilation wouldn’t work without them.

Once I installed those tools, I got everything running smoothly.

Here’s what my project file looks like:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PlatformTarget>x86</PlatformTarget>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <OutputType>Library</OutputType>
    <SelfContained>true</SelfContained> <!-- Bundle runtime for standalone execution -->
    <PublishAot>true</PublishAot>       <!-- Enable Native AOT compilation -->
  </PropertyGroup>
</Project>

If you’re using the command line to publish, the PlatformTarget and RuntimeIdentifier aren’t strictly necessary, as the -r option specifies the runtime. However, I left them in so I could publish directly from the IDE.

For publishing via the command line, even if PublishAot isn’t set in the project file, you can still use:

dotnet publish -c Release -r win-x86 -p:PublishAot=true

Note: For anyone reading along, this process compiles the runtime components of .NET 8/9 directly into the output, which can make the generated DLL somewhat large. For example, I created a simple DLL with two methods to expose C# regex functionality, and the compiled DLL came out at 1.55 MB.

Edit: Clarification added — AOT Win32 is only supported in .NET 9 and up. (Edited on 24th Dec 2024)

This was done in .NET 9, which apparently has better trimming to reduce output size.

Mark

x86 compilation is only available since DotNet 9 - so it’s a requirement when used with Clarion.
I myself don’t use Visual Studio anymore - instead I use Visual Studio Code with the new DotNet extension.

Also, you haven’t set that it trims the output in the project, best is to add:

<PublishTrimmed>true</PublishTrimmed>

To be more precise, I have a Directory.Build.props, which I add by default to each Clarion library I write so it’s setup how I want it - NOTE, this also changes where the output is written to so it is easier to use scripts to deploy it, it also sets up some defaults for Source generator as I am working on a Clarion Code generation based on the XML docs file:

<Project>
    <PropertyGroup>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <ArtifactsPath>$(MSBuildThisFileDirectory)\Out</ArtifactsPath>
        <CompilerGeneratedFilesOutputPath>$(MSBuildThisFileDirectory)\Out\.generated</CompilerGeneratedFilesOutputPath>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <ImplicitUsings>enable</ImplicitUsings>
        <JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
        <LangVersion>preview</LangVersion>
        <!-- Disable warning CS1591: Missing XML comment for publicly visible type or member -->
        <NoWarn>1591</NoWarn>
        <Nullable>enable</Nullable>
        <PublishAot>true</PublishAot>
        <PublishTrimmed>true</PublishTrimmed>
        <RootNamespace>{ROOTNAMESPACE}</RootNamespace>
        <RuntimeIdentifier>win-x86</RuntimeIdentifier>
        <TargetFramework>net9.0-windows</TargetFramework>
        <TrimMode>link</TrimMode>
        <UseArtifactsOutput>True</UseArtifactsOutput>
    </PropertyGroup>
</Project>

Everything mentioned here, doesn’t need to be mentioned inside your .csproj file - it sort of works a default for the project by sln file, so each csproj referenced by the sln inherits these defaults (and the paths are based on the sln)

1 Like

So it is, sorry for the miss information, I’ll update my post.

Mark

Just updated mine with more information