views:

1173

answers:

3

I have an EXE loaded into a byte array, and I am trying to load it into an assembly object using Assembly.Load. I am getting errors trying to load.

Here is the code that is causing the exception:

Assembly a = Assembly.Load(bin);

bin is my byte array, loaded from the EXE.

Here is the exception I am getting:

Could not load file or assembly '109590 bytes loaded from calc_tester, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Any help is appreciated.

A: 

I am not sure, but because it is an EXE, it might be failing because of the unmanaged headers in the EXE?

Why not just do a LoadFrom( filename )?

Rob Prouse
+4  A: 

Make sure the file you're trying to load is a .NET Managed exe/dll.

arul
I am using windows calculator as a test, will this work?
Won't. Calc isn't managed.
VVS
Thats the problem, thanks david / arul!
A: 

Did you ever figure out a solution to this issue? I myself am running across this issue and have yet to figure out why I can't load a byte array back into the appdomain.

If you do have a solution, it would be great if you can post it here..

Chaitanya

Chico