Questions on ngen.exe RRS feed

  • Question

  • When I run

    ngen.exe install imageName.exe
    , and I examine the output under
    dumpbin /disasm
    , why does is File Type: DLL instead of EXE? Also, why is there still a CLR header in the native image PE? Isn't the CLR header only necessary if the PE contains managed code? I'm assuming the CLR header is the same as the ".NET header" described in this article.


    However, if the output of ngen.exe is an image with native machine code, then why would the native image need to contain managed code; why would it need a CLR header? 

    Lastly, how do you actually run the output native image from ngen? If I try to run it as-is from the command line, I get the error, " is not a valid Win32 application". The documentation doesn't appear to show how to run or use the ngen'd image.


    T. Webster

    Thursday, April 28, 2011 1:16 AM


  • The output file is not a native image (we can call it a "mixed image"), but a managed image which contains native methods.


    When we run imageName.exe, CLR will check whether there is a matched "mixed image", if so, methods of imageName.exe will not be JIT-ed again, since the has corresponding native methods, hence reduce load time of our application.


    The "mixed image" cannot run standalone, it needs CLR to load into memory, so the "mixed image" has a CLR header (and other managed parts) to make CLR to recognize its content.


    The ngen-ed image of imageName.exe is, from my understanding, the actual extension of ngen-ed image should be".ni", the ".exe" extension is added to keep consistence with its original assembly:  imageName.exe;

    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by T. Webster Thursday, April 28, 2011 12:08 PM
    Thursday, April 28, 2011 7:27 AM