Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exported function present when building debug, missing from published #235

Open
ggegoge opened this issue Sep 5, 2024 · 1 comment
Open
Labels

Comments

@ggegoge
Copy link

ggegoge commented Sep 5, 2024

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

  1. am I doing something wrong to miss the runtime? when running the c# function from c# it works
  2. 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: 
@3F
Copy link
Owner

3F commented Sep 7, 2024

Hello,

The publish directory has already been discussed earlier #224 (comment)

It seems I need to add something like this later for automatic generation in future versions.

But this is not the problem in your case:

Could not load file or assembly 'System.Runtime, Version=8.0.0.0,

3F/DllExport project does not officially support the modern .NET 8 platform yet (1.7.4). I apologize for the inconvenience.

FYI: you can temporarily add <LangVersion>latest</LangVersion> to support some modern language features on older target platforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants