Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

c# - .NET 4.0 BadImageFormatException on Assembly.Load()

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...