What is the purpose of Ngen.exe in .NET?

On compiling your source code, it will be converted to intermediate language which is then converted to machine code. The role and purpose of Ngen.exe in this process is shown below:

Image

As shown in the diagram above, you can use Ngen.exe to convert MSIL to machine code. This machine code will then be stored in native image cache. When there is a need for restoring it, it loads it from cache and not from the hard disk. Hence it will make the execution faster and improve performance.

You can execute Ngen.exe using the following command:
ngen.exe install sampleAssembly
Here sampleAssembly is the assembly name.

C# gives you yet another provision to schedule your assembly for precompilation. This is done using the command shown below:
ngen.exe install sampleAssembly / queue: 1

This 1 refers to the priority. Priority takes the value of 1 or 2 or 3. Precompilation of assemblies queued with priority 1 and 2 will be precompiled forcefully. But if you mention the priority as 3 then the precompilation will be done only when the machine is idle.

So far you have seen how to install assemblies using Ngen.exe. Similarly you can also uninstall an assembly that is already installed using Ngen.exe. This is established using the following command:
ngen.exe uninstall sampleAssembly

But one thing interesting and most important about this utility is that, native images generated using ngen.exe cannot be deployed in the server. They have to be created at the client side. For that, you have to include the above shown commands into your setup file which will be executed at the client side.

Characteristics of Ngen.exe:

• Not any user can run this Ngen.exe. Only users who have administrative privileges can execute this executable

• Loading is comparatively faster when compared to MSIL because loading is done from cache and not from hard disk

• The images generated using Ngen.exe facilitate code sharing across processes

• After generating native image, if you perform any change in the assembly then you have to ensure that you update the image as well

• A drawback while using Ngen.exe is that it requires more time to generate and the image that is created requires considerably more memory for storage

| How do you prevent a class from overriding in .NET? | How are classes related to objects in .NET Application | How are Delegates different from Events in .NET? | How are system exceptions different from application exceptions in .NET? | How are Value Types different from Reference Types in .NET? | How can a finalize method be suppressed in .NET? | How can you call Stored Procedure in ADO.NET? | How can you force Dispose method to be called automatically in .NET? | How do you call a Base Class Constructor from Derived Class Constructor in .NET? | How do you connect your VB.NET application to SQL Server? | How do you implement Cloning in .NET? | How do you implement Façade Design Pattern in .NET? | How do you implement MVC Pattern in ASP.NET? | How do you install .NET Assembly in GAC? | How is shadowing different from overriding in .NET? | How to prevent a particular .NET DLL from being decompiled? | Illustrate Delay Signing Process of an Assembly in .NET? | What are Reference Types in .NET? | What are the advantages of C#? | What are the advantages of VB.NET? | What are the differences between Namespace and Assembly in .NET? | What are the similar features between class and structure in .NET? | What are Value Types in .NET? | What do you mean by mixed mode authentication in .NET? | What do you mean by Satellite Assembly in .NET? | What do you mean by shadowing in .NET? | What is CTS in .NET? | What is ILDASM in .NET? | What is Managed Code in .NET? | What is Manifest in .NET? | What is MSIL in .NET Framework? | What is the importance of finalize method in .NET? | What is the need for Visitor Pattern in C#? | What is the purpose of bindingRedirect tag in web.config file of .NET? | What is the purpose of CodeDom in .NET? | What is the purpose of dispose method in .NET? | What is the purpose of Ngen.exe in .NET? | What is the purpose of Strong Name in COM Components of .NET? | What is the purpose of virtual keyword in .NET? | What Object Oriented Principles can be incorporated in .NET Application? |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.