【发布时间】:2013-11-05 14:16:54
【问题描述】:
情况
我在安装过程中使用 ngen 创建我的程序集的本机映像。直到最近这才正常工作,我不知道是什么破坏了它。遗憾的是,ngen 输出并不是很有帮助。它只是说它无法找到或加载一个类型,但没有说明是哪种类型。
非常奇怪的是,只有当我的程序集是使用 msbuild 构建时(由 TFS Team Build 或我自己在命令行中运行),ngen 才会失败,但如果我使用 Visual Studio 2010 构建它,ngen 工作正常!我已经从 .NET 4.0(我的本地机器)、.NET 4.5(TFS 2012 Update 3)和 .NET 4.5.1(TFS 2013)尝试了 msbuild,都在 ngen 中导致了相同的错误。它只是 Visual Studio 2010 GUI 中的构建有效。但是错误只发生在 ngen 中,运行时行为是相同的 - 它回退到 IL 程序集,但工作正常。
我什至尝试调试 ngen.exe 和 mscorsvw.exe,但我只能看到引发了一些本机异常,其中之一是 EETypeLoadException,但我无法获得有关异常的其他信息。但是在调试原生应用程序方面我一点经验都没有。
问题
有谁知道我如何获得有关 ngen 错误的更多信息?导致错误的类型的名称会很好。
我已经在某处读到 Visual Studio 不只是调用 msbuild 进行构建,但为什么会有这么大的差异?
其他信息
TFS 在自动构建期间运行 msbuild。没有配置额外的 msbuild 参数,并且构建过程模板是 TFS 2012 Update 3 中的默认模板。
当我自己运行 msbuild 时,我在 Visual Studio 中也使用的同一文件和文件夹上使用以下命令。配置和平台也是 Visual Studio 中的活动并在 TFS 构建中选择。
msbuild Solutionname.sln /t:Rebuild /p:Configuration=Release /p:"Platform=Mixed Platforms"
ngen 错误发生在我测试的所有机器上,所以它不是我的安装所特有的。
这是完整的 ngen 输出,即使使用了详细开关:
C:\Program Files (x86)\MyProgram>ngen install MyProgram.exe /verbose
Microsoft (R) CLR Native Image Generator - Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Installing assembly C:\Program Files (x86)\MyProgram\MyProgram.exe
1> Compiling assembly C:\Program Files (x86)\MyProgram\MyProgram.exe (CLR v4.0.30319) ...
1>Error compiling C:\Program Files (x86)\MyProgram\MyProgram.exe: Could not find or load a type. (Exception from HRESULT: 0x80131522)
1> Finished compiling assembly C:\Program Files (x86)\MyProgram\MyProgram.exe ...
1>Ngen failed to generate native code for image C:\Program Files (x86)\MyProgram\MyProgram.exe because of the following error: Could not find or load a type. (Exception from HRESULT: 0x80131522)
1>Ngen will retry compilation of image C:\Program Files (x86)\MyProgram\MyProgram.exe
1> Compiling assembly C:\Program Files (x86)\MyProgram\MyProgram.exe (CLR v4.0.30319) ...
1>Error compiling C:\Program Files (x86)\MyProgram\MyProgram.exe: Could not find or load a type. (Exception from HRESULT: 0x80131522)
1> Finished compiling assembly C:\Program Files (x86)\MyProgram\MyProgram.exe ...
1>Uninstalling assembly C:\Program Files (x86)\MyProgram\MyProgram.exe because of an error during compilation: Could not find or load a type. (Exception from HRESULT: 0x80131522)
Could not find or load a type. (Exception from HRESULT: 0x80131522)
【问题讨论】:
-
如果有人遇到同样的问题:在客户端机器(运行 ngen 的机器)上安装 .NET Framework 4.5.1 为我解决了问题。
标签: c# .net visual-studio-2010 msbuild ngen