.NET interview questions: - What is Native Image Generator (Ngen.exe)? Does NGEN.EXE always improve performance?
NGEN stores full compiled.NET native code in to cache. In other words rather than dynamically compiling the code on run time a full image of native compiled code is stored in cache while installing the application. This leads to better performance as the assembly loads and execute faster.
In order to install full compiled native code in cache we can execute the below command line from your visual studio command prompt.
NGEN.EXE on improving performance: -
No, it’s not always necessary that ngen.exe produces optimized code because it uses the current environments parameters which can change over a period of time. For instance a code compiled in windows XP environment will not be the optimized code to run under windows 2008 server. So we need to once test with ‘NGEN’ and without ‘NGEN’ to conclude if really the performance increases.
Also see .NET interview questions video on IL code, CLR, CTS, CAS: -