Search code examples
c#.netngen

Which ngen to use for x86 app on x64 system?


I decided to ask this question because did not find clear answer. My WPF program is x86 (.Net 4.5.2). I use Inno Setup to install and create ngen image. Should I use Microsoft.NET\Framework64\v4.0.30319\ngen.exe when installing on 64bit system and Microsoft.NET\Framework\v4.0.30319\ngen.exe when installing on 32bit system or because the program is x86 I should allways use Microsoft.NET\Framework\v4.0.30319\ngen.exe?


Solution

  • This is easy to just try yourself by running ngen.exe from the command line. That mixing can't work is crystal clear, it is very chatty about it. I edited the output to the core message:

    1>Ngen failed to generate native code for image C:\projects2\ConsoleApplication491\bin\Debug\ConsoleApplication491.exe because of the following error: The image file is not compatible with the version of Ngen you're running. Use 32bit Ngen for 32bit assemblies, and 64bit Ngen for 64bit assemblies. (Exception from HRESULT: 0x80131F07)

    Produced with a little test project that targets x86 and running the 64-bit version of ngen.exe.