C
C#3w 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
333fred3w ago
So, Roslyn is not capable of emiting an actual executable file on modern .NET
333fred
333fred3w 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
TheSnowOwl3w 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
333fred3w 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
TheSnowOwl3w 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
More Posts
✅ I need help with positioning the news under weather, stock, and time. https://paste.ofcode.org/v3i tried by using Cursorposition but it didn't work for some reason.Put a pdf in a formI want to select a pdf from the pc and format it in a button or something. When I press the button t✅ EF Core - Not getting updated data from PostgreSQL tableI have the following method in my `DbService.cs` ```csharp public async Task<long?> GetLastDumpTimeSHow do I implement the Chrome API Sidepanel with a Blazor browser extension?Posted the question with more details here: https://stackoverflow.com/questions/78640477/how-do-i-u✅ Need Help making a Loader for a game.I just need someone to tell me what to Fix. 2 Erros and 1 warrning not really sure what to do and YeQuestPDF Why does the document become empty after adding the table and how to fix it?I have a pdf file that I generate using code, I'm trying to add a table to it that is contained in c✅ [Solved] Dotnet restore is failing on new appsI'm working with the CLI on linux. Any new app I create (console, web api, etc) running dotnet restoI am new to C# and would like to hear about all the resources(paid or not) where I can learn C#.The title kind of explains it all. If you suggest paid content, Please put up how much the program/cpng image but background is not transparentCan somebody help me out? The original image is attachedProblem with TimerButton works only once - when I want to click again then nothing happens, I need to launch again