Ngen error because "Mscorlib.dll does not have a native image" (x64 only, .NET 4.0 only)

StackOverflow https://stackoverflow.com/questions/18683021

  •  28-06-2022
  •  | 
  •  

سؤال

I'm trying to generate a native image of my .NET 4.0 application using Ngen using a 64-bit Windows 7. When Platform is set to x64 (or Any CPU) - Ngen fails, complaining that 'NGen cannot proceed because Mscorlib.dll does not have a native image.'

When compiling as x86 and using the appropriate Ngen - it works fine. Also, when changing the .NET version to 2.0 - it works. (When trying to Ngen the x64 application with the x86 Ngen, it tells me I should use the 64-bit version.)

More information:

This is (part of) what I see in CMD: The ellipses (= ...) are present in the original.

1> Compiling assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 (CLR v4.0.30319) ...

1>mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

.

2> Compiling assembly Accessibility, Version=4.0.0.0, Culture=neutral, Public KeyToken=b03f5f7f11d50a3a (CLR v4.0.30319) ...

.

2>Ngen failed to generate native code for image Accessibility, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a because of the following error: NGen cannot proceed because Mscorlib.dll does not have a native image (Exception from HRESULT: 0x80131F06)

Searching inside C:\Windows\assembly I found 3 mscorlib.dll's. One in GAC_32, one in GAC_64 (both in subfolders beginning with 2.0.0.0) and one in a subfolder temp.

When searching inside C:\Windows\Microsoft.NET I found six of them: two under assembly (in GAC's 32 and 64) both in folders that begin with 'v4.0...', and four in Framework's: 2 in Framework, and two in Framework64 (in each - one in 'v2.0...' and one in 'v4.0...').

Does this mean that only .NET 2.0 mscorlib's are really run as native images (when needed)? And why doesn't Ngen succeed in saving native images of .NET 4.0?

Bottom line: How do I create a native image of a .NET 4.0 application that targets x64?

هل كانت مفيدة؟

المحلول

This is unhealthy. The ngen-ed image of mscorlib.dll should have been created when .NET was installed on your machine. It is located in c:\windows\assembly\NativeImages_v4.0.30319_64\mscorlib\ab0a8fc3d086a3aaf942f366a12a9185\mscorlib.ni.dll. I'm not sure how well the hashed part of the directory name repeats from one machine to another.

You cannot see this file with Windows Explorer, you must use the command prompt. Go check to see if it there, something went seriously wrong when .NET was installed if it is missing. The ".NET Runtime Optimization Service" is the one that gets that job done, make sure you didn't disable it.

A standard mistake is running ngen.exe from a command prompt that isn't elevated.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top