C
C#6mo ago
TheSnowOwl

✅ I need help with compiling an console application exe with the Roslyn compiler

Hi there, ive been working on a funky little program for fun, and its basically supposed to be a weird and very unpractical "visual scripting" ish kind of thing. However instead of having it be saved as a pure intermediate instruction set, i want it to be able to be compiled to an actual C# application. i have gotten a .exe file compiled without any diagnostics errors, however when i try to run the application it it greets me with an error. Unhandled Exception: System.TypeLoadException: Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist. i have these files in the output derectory, where the deps.json and runtimeconfig.json are generated by some of my code and thus i have no clue if they are right. https://paste.ofcode.org/Zwv6auNsjBkkSU29JQZE3x Here is my compilation class (i know, its extremely ugly but its my first time trying this. I intend to refine everything once i got it working at least)
No description
5 Replies
333fred
333fred6mo ago
So, Roslyn is not capable of emiting an actual executable file on modern .NET
333fred
333fred6mo ago
I would start by pulling out your AddDefaultReferences method and just use https://github.com/jaredpar/basic-reference-assemblies
GitHub
GitHub - jaredpar/basic-reference-assemblies: Produce NuPkg files t...
Produce NuPkg files that have .NET Reference assemblies as resources - jaredpar/basic-reference-assemblies
TheSnowOwl
TheSnowOwlOP6mo ago
interesting, as it is able to compile to a .exe, i expected i would be able to emit an executable file. anyway, could you explain a little more what you mean with AddDefaultReferences, and the github page you send? also, i seem to have forgotten that i do have the references to required assemblies given to the code compilation object, even before making my post here
333fred
333fred6mo ago
You choose the name. Just because something is named .exe doesn't make it an executable file When you try and run it, it's going to try and run on framework Which will obviously not work With AddDefautlReferences, you're committing the mistake of attempting to manually package up the references from the current process The README of basic reference assemblies covers why this is a bad thing, particularly for .NET Core/5+
TheSnowOwl
TheSnowOwlOP6mo ago
i see, thanks a lot! with a bit of fiddling around i have managed to get it to work
Want results from more Discord servers?
Add your server