3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
967 stars 133 forks source link

How to chain link C# Dlls? #226

Open mea05pb opened 1 year ago

mea05pb commented 1 year ago

. . .

The question is related to:

Maybe a silly question, sorry I am still learning

When trying to access C# DLLs from native C++ I always get : EEFileLoadException at memory location when the C# assembly (decorated with [Dllexport]) is using other references. I have tried putting all the required Dlls into the folder with the C++ exe but this doesn't help.
So in other words I am accessing C# assembly A from C++ and assembly A is using assemblies B,C,D etc and C++ seems to not be able to resolve these links. (I am using ILmerge in pre-processing tab)

3F commented 1 year ago

Hello,

Did you list all mentioned dependencies in that field of merging modules?

It's hard to say without inspecting. I recommend isolating the problem using AssemblyResolve to check the generated module after ILMerge

sidpara47 commented 5 months ago

I'm facing the same problem . Calling the c# dll from rust.

3F commented 5 months ago

@sidpara47 Have you tried tracking attempts to load requested modules into the active domain? Are you using module merging somehow in your projects? What about applied resolution of an assembly fails in your code? What DllExport configuration? Can you prepare a minimal reproducible example to understand the issue? I need some details. Thanks.

sidpara47 commented 5 months ago

@3F https://stackoverflow.com/questions/78636084/i-want-to-call-a-c-sharp-dll-file-from-rust-code follow this link , you will find everything you need.

3F commented 5 months ago

@sidpara47

https://stackoverflow.com/questions/78636084/i-want-to-call-a-c-sharp-dll-file-from-rust-code follow this link , you will find everything you need.

I don't see anything I requested. I'm not even sure you're using this DllExport project. What version? What configuration?

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'NAudio.Wasapi, Version=2.2.1.0, Culture=neutral, PublicKeyToken=e279aa5131008a41' or one of its dependencies. The system cannot find the file specified

I've verified that NAudio.Wasapi is referenced correctly in the C# project and is available in the same directory as the DLL.

Custom assembly resolving may still be required for your module MicMonitorDllNetFramework.dll because CLR is initialized for this module by the module (host) written in Rust in that case and valid paths for that modified module can point to the different (host) directories and system path of course. Btw, you can quickly verify this by temporarily moving NAudio.Wasapi and all its dependencies into system32 directory, should help.

Additional Details: I am primarily a C# developer

So please backtrace all module loading in your domain. You can additionally check Debug - Windows - Modules (VS IDE) etc. Also you can try any custom pre-loading at the very first call (important, as you know) of a type from NAudio.Wasapi module and so on.

And again, what version and configuration please. Thanks.