DllExport
DllExport copied to clipboard
exported function present when building debug, missing from published
tldr
The issue is the following: I manage to create a DLL with my c# functions exposed to C++. But I miss the runtime then, When I try to publish the dll as self contained to generate other DLLs, I am missing the function from the DLL. I believe that the Dll in publish doesn't get modified. Path: to the published dll:
\bin\Release\net8.0-windows\publish\win-x64\*
Question
- am I doing something wrong to miss the runtime? when running the c# function from c# it works
- for the published version: am I doing something wrong to miss the function there or is it a bug that this dll doesn't get modified?
more details
I have simple C# code:
public class EntryPoint
{
[DllExport(CallingConvention = CallingConvention.StdCall)]
public static void StartApplication()
{
Console.WriteLine("Application started from C# DLL!! !");
}
}
it is in a project targeting .NET 8.0. When running the following c++ code:
int main()
{
HMODULE appModule = LoadLibraryEx(L"Dummy.dll", nullptr, 0);
auto startApplicationFunction = GetProcAddress(appModule, "StartApplication");
startApplicationFunction();
return 0;
}
I was using the DLL by simply building the project in visual studio
I am missing the runtime: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies
I tried to publish the DLL as self contained and then I would paste all of the required DLLs to see if then having System.Runtime.dll clearly in path fixes the issue but the problem then is that the dll created this way does not contain the StartApplication function
for the self contained build:
<PropertyGroup>
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\Release\net8.0-windows\publish\win-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>
the csproj for the project itself is dotnet new classlib
+ DllExport's additions
The question is related to:
-
DllExport -version
: v1.7.4.29858+c1cc52f - Copy-paste from
Data
tab:
Installed: True; 1.7.4+c1cc52f; invoked: 1.7.4
Project type: CsSdk
Storage: ProjectFiles
Compiler.Platform: x64
Compiler.ordinalsBase: 1
Compiler.rSysObj: False
Compiler.ourILAsm: False
Compiler.customILAsm:
Compiler.genExpLib: False
Compiler.peCheck: PeIl
Compiler.patches: None
PreProc.Type: None
PreProc.Cmd:
PostProc.Type: None
PostProc.ProcEnv: $(SolutionPath);$(MSBuildThisFileFullPath)
PostProc.Cmd:
SignAssembly:
Identifier: D6E9CEF1-38CE-43E7-8B38-38A42767B83C
Instance: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe
Project path: Q:\source\Dummy\Dummy\Dummy\Dummy.csproj
Action: Configure
PlatformTarget: x64
TargetFramework: net8.0-windows
TargetFrameworks:
TargetFrameworkVersion:
RootNamespace:
AssemblyName:
MgrArgs:
MetaLib: tools\raw\lib\net20\DllExport.dll
MetaCor: tools\raw\lib\netstd\DllExport.dll
Proxy:
StoragePath: .net.dllexport.targets
ddNS: System.Runtime.InteropServices
ddNS max buffer: 500
UseCecil: True
intermediateFiles: False
timeout: 30000
Options: None
RootPath: Q:\source\Dummy\Dummy\
PkgPath: Q:\source\Dummy\Dummy\packages\\DllExport.1.7.4\
SlnFile:
SlnDir: Q:\source\Dummy\Dummy\
DxpTarget: tools\net.r_eg.DllExport.targets
MsgGuiLevel: -1
LockIfError: