C#C
C#12mo ago
Get

PersistedAssemblyBuilder to generate executable

Hello! I'm trying to generate IL executable from C# via PersistedAssemblyBuilder.
I'm running into issues where the generated IL throws an exception:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

I'm not sure if I did something wrong as I followed the docs https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-reflection-emit-persistedassemblybuilder or even if I tried to copy and paste the code directly (SetEntryPoint() example with output path modification, shown in screenshot), it still gives me error when I run the exe. I definitely have .NET 9 installed (as I need .NET 9 to actually run this exe generator in the first place).

Can someone help me figure out what went wrong? And how can I fix it so that it runs fine?
image.png
image.png
Was this page helpful?