Basics: I want it to be able to run an EXE in memory without touching the disk, so that when I close the program, all data is left in the RAM for purging (I have a plan on how to do this; I know the code attached will not achieve this by itself).
I load the raw EXE into an assembly:
var exe_assembly = Assembly.Load(memStream.ToArray());
*NOTE: memStream contains the raw-bytes of an EXE (x64) program, loaded into a memory stream
When I go to build the solution, a System.BadImageFormatException is thrown at this line, stating:
System.BadImageFormatException: 'Could not load file or assembly. 1672920 bytes loaded... An attempt was made to load a program with an incorrect format.'
Now, Google is filled with solutions like these: "An attempt was made to load a program with an incorrect format" even when the platforms are the same
Where you must enable the correct Platform CPU Target... I have changed my project and build settings so they are both 64-bit, and made triple sure that the EXE being loaded into the assembly is also a 64-bit executable. I have even tried changing the build settings to x86, to rule out any problems with x64 bit entirely.
I am brand new to C# / Visual Studio, so if you think I missed a simple step, it could be the solution :)
question from:
https://stackoverflow.com/questions/65640755/net-4-0-badimageformatexception-on-assembly-load 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…