❔ Native DLL in source generator

I am trying to make source generator that relies on custom native DLL, compiled from Rust. But Issue I am facing issues with managing it to be able to load them.
CSC : warning CS8785: Generator 'HybridByondCodeGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'DllNotFoundException' with message 'Unable to load DLL 'dreammaker' or one of its dependencies: The specified module could not be found. (0x8007007E)' [C:\Projektai\ExternalByondSharp\ExtBySharp.Game\ExtBySharp.Game.csproj]
CSC : warning CS8785: Generator 'HybridByondCodeGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'DllNotFoundException' with message 'Unable to load DLL 'dreammaker' or one of its dependencies: The specified module could not be found. (0x8007007E)' [C:\Projektai\ExternalByondSharp\ExtBySharp.Game\ExtBySharp.Game.csproj]
ExtBySharp.Generator is project containing HybridByondCodeGenerator DMNet.SpacemanDMM is project containing native bindings and wrapper for native DLL. libdreammaker.a and dreammaker.dll are native DLLs. ExtBySharp.Game is project for containing generator source files *.dm and *.dme and needs code to be generated for. I tried renfrecing project directly, but it didn't work, then I ended up packaging it as nuget package, and generator seems to load things, just it fails at loading native dlls, I tried putting them under analyzers/dotnet/cs, build/ and I am out of idea what to try.
8 Replies
333fred
333fred3y ago
Do not do IO in your generator. It is not supported Loading a native assembly is IO
Karolis2011
Karolis2011OP3y ago
Does this mean I need to translate everything in to intermediate things via custom program and then compile them via source generator in to final csharp?
333fred
333fred3y ago
I'm not entirely sure what you're describing. Can you be more specific? What is the intermediate thing you mean here?
Karolis2011
Karolis2011OP3y ago
Aka make console program that transforms things and loads dm and dme files, via native dll and then emit files thar are 80% transformed and then use sourcegenerator to load them and do final pass to compile them in to csharp?
333fred
333fred3y ago
That sounds like it would work. You could make it an msbuild task that runs before CoreCompile And then you include those transformed things as additional files and retrieve them from the AdditionalFilesProvider
Karolis2011
Karolis2011OP3y ago
Yeah, then that is solution, I think I am going to try 🙂
333fred
333fred3y ago
Also, remember that #roslyn exists and more of the team monitors that channel for questions (Or if you didn't know, now you do 🙂 )
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server