DllExport icon indicating copy to clipboard operation
DllExport copied to clipboard

How to use DllExport on C# .NET8.0 ?

Open ANopony opened this issue 1 year ago • 5 comments

Hi, I have create a liberary project using .NET8.0. And I want to package my project and .NET8.0 Runtime into a .dll file so that everyone can use it on their project, whether they have a .NET environment or not. That's why I'm long for a usage or a demo which shows how to use DllExport on C# .NET8.0. I'm looking forward to your early reply. Thanks.

ANopony avatar Feb 27 '25 02:02 ANopony

Hello,

Here you can find Demo -> ExtDotNetCoreLibrary4 (net9.0;net8.0;netstandard2.1) that was configured for basic netcore assemblies with multiple targeting.

For other types it's better to see actual Unit tests, like: https://github.com/3F/DllExport/blob/master/src/DllExport/assets/NetCoreAsset/Basic.cs (net9.0;net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netstandard2.1;netstandard2.0)

git clone https://github.com/3F/DllExport.git DllExport
cd DllExport & DllExport.assets.cmd

Use DllExport.assets.cmd to see used configurations; and actual code using assets.sln and DllExport.sln -> UnitedTest https://ci.appveyor.com/project/3Fs/dllexport-ix27o/builds/51594290/tests

3F avatar Feb 27 '25 11:02 3F

It worked fine with NetFW4.x in the old version. (Still work with 4.X and with 1.8.1) When it didn't work with your latest version for .NET 9, I tested your example. However, I got the same error. The error is in the image.

Note: For Excel VBA, the CallingConvention must be StdCall.

Image

Zeki-Gursoy avatar Sep 30 '25 12:09 Zeki-Gursoy

@Zeki-Gursoy

I tested your example. However, I got the same error.

Each project must be configured individually depending on the specific case. See related #250 and #253. The explanation can also be found in #219

3F avatar Oct 04 '25 12:10 3F

Each project must be configured individually depending on the specific case. See related #250 and #253. The explanation can also be found in #219

Despite repeated efforts, I couldn't create a DLL that worked with NET9 and 1.8.1. Therefore, I reverted to version 1.7.4.

However, this version had issues attaching/installing to NET7+ projects, requiring several installs/uninstalls or manually referencing the package folder (to prevent the IDE from underlining the DllExport attribute in red).

EDIT: I've added the NET9 working project with 1.7.4. If you fix the install issue, you can release a new version as 1.7.5...

ClassLibrary1.zip

I'm attaching screenshots of the DLL project configuration I created for VBA with NET9.

Image Image

.

using System.Runtime.InteropServices;

namespace ClassLibrary1
{
    public class Class1
    {
        [DllExport(CallingConvention.StdCall, ExportName = "Deneme")]
        public static int deneme()
        {
            return 10;
        }
    }
}

Zeki-Gursoy avatar Oct 06 '25 20:10 Zeki-Gursoy

@Zeki-Gursoy hmm... 1.8.x just extends support through the same rebasing feature. But it sounds like a bug if 1.7.4 works correctly in your case.

I will look into the issue later. Thanks for the prepared ClassLibrary1.zip !

3F avatar Oct 09 '25 00:10 3F