The question is simple: i've generated an executable with ngen
, his full path is:
"C:\Windows\assembly\NativeImages_v4.0.30319_32\NassilDotNet\eddb174e4a81e440633abddb977ab57a\NassilDotNet.ni.exe"
When I try to open/execute that executeable, an Error Message Dialog is displayed: This application cannot be runned on your system. Please, contact computer administrator (etc)...
The original executeable shows an Hello World message on Console.
What i'm doing wrong?
There are several differences in ngen assemblies from the normal ones. First, they are always marked IL_LIBRARY
, even if they are executable. You can see this if you open the manifest in ildasm:
.corflags 0x00000004 // IL_LIBRARY
Whereas normal assemblies usually have .corflags 0x00000001
(ILONLY
) even if they are only libraries.
Second, (even though they are .exe), the standard PE entry point is missing (and the DOS entry point is missing too). It doesn't really matter much for CIL executables, but there are already two signs to tell the system it shouldn't execute the executable.
I thought a code like this could work:
Assembly ass = Assembly.LoadFile(path);
ass.EntryPoint.Invoke(null, new object[]{new string[]{}});
But I always get BadImageFormatException in LoadFile. Strangely, I don't get this exception if I load a library file this way, but that has no entry point that can be invoked.
I suppose you can disassemble the file with ildasm, change the .corflags
field and use ilasm to produce an executable. However, this will strip the native code present in the file and turn it basically to the original executable.
To sum this up, just run the original file. ngen files are part of the framework infrastructure and aren't meant to be deployed or run directly.