Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET native images created with NGEN are not loaded

I have used NGEN to create native images of several assemblies used by my application. However, those images are not loaded when running the application and I have no idea why.

This is a typical log from fuslogvw:

*** Assembly Binder Log Entry  (2/05/2012 @ 13:29:04) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\MyDir\MyApp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = ***\***
LOG: DisplayName = MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified)
LOG: Appbase = file:///C:/MyDir/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApp.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: Start binding of native image MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\MyDir\MyAssembly.dll.

And the information from ngen.exe about that assembly:

C:\MyDir>ngen display MyAssembly.dll
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

NGEN Roots:

C:\MyDir\MyAssembly.dll

NGEN Roots that depend on "C:\MyDir\MyAssembly.dll":

C:\MyDir\MyAssembly.dll

Native Images:

MyAssembly, Version=1000.0.0.0, Culture=neutral, PublicKeyToken=null

I used the ngen.exe located in C:\Windows\Microsoft.NET\Framework\v4.0.30319\ and my assembly's target framework is .NET Framework 4. I didn't recompile the assembly after having created the native image.

Any help would be appreciated.

like image 773
Odsh Avatar asked May 02 '12 12:05

Odsh


People also ask

Where is NGEN installed?

Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer.

Does NGEN improve performance?

The Ngen.exe (Native Image Generator) tool creates native binary images (files containing compiled processor-specific machine code) for assemblies. This improves CodeRush performance because it produces and installs binary images in the native image cache on the local computer.

What is .NET native image?

The Native Image Generator, or simply NGen, is the ahead-of-time compilation (AOT) service of the . NET Framework. It allows a CLI assembly to be pre-compiled instead of letting the Common Language Runtime (CLR) do a just-in-time compilation (JIT) at runtime.


1 Answers

Assembly manager loaded from: C:\Windows\Microsoft.NET\ Framework64\v4.0.30319\clr.dll

Your process is running in 64-bit mode, the default with the AnyCPU target on a 64-bit operating system. That requires that you run the 64-bit version of ngen.exe. Be sure to select the proper Visual Studio Command Prompt. There are two, the one that sets up the environment for 64-bit tools is named "Visual Studio x64 Win64 Command Prompt (2010)" in the Start menu.

like image 59
Hans Passant Avatar answered Sep 28 '22 22:09

Hans Passant