Dot-Net

未載入使用 NGEN 創建的 .NET 本機映像

  • April 5, 2013

我使用 NGEN 創建了我的應用程序使用的幾個程序集的本機圖像。但是,這些圖像在執行應用程序時沒有載入,我不知道為什麼。

這是來自 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.

以及來自 ngen.exe 關於該程序集的資訊:

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

我使用了位於 C:\Windows\Microsoft.NET\Framework\v4.0.30319\ 中的 ngen.exe,我的程序集的目標框架是 .NET Framework 4。創建本機映像後,我沒有重新編譯程序集。

任何幫助,將不勝感激。

從以下位置載入程序集管理器:C:\Windows\Microsoft.NET\ Framework64 \v4.0.30319\clr.dll

您的程序在 64 位模式下執行,預設是 64 位作業系統上的 AnyCPU 目標。這要求您執行64 位版本的 ngen.exe。請務必選擇正確的 Visual Studio 命令提示符。有兩種,一種是為64位工具設置環境的,在開始菜單中命名為“Visual Studio x64 Win64 Command Prompt (2010)”。

引用自:https://stackoverflow.com/questions/10413987