情况
在安装过程中,我使用ngen创建程序集的本机映像。直到最近,这一切都运行得很好,我不知道是什么破坏了它。遗憾的是,ngen输出没有多大帮助。它只是说它无法找到或加载类型,但没有说明是哪种类型。
非常奇怪的是,只有当我的程序集是使用msbuild (由TFS Team build或我自己在命令行中运行)构建时,ngen才会失败,但如果我使用Visual Studio2010构建它,ngen就可以正常工作!我尝试了.NET 4.0 (我的本地机器)、.NET 4.5 (TFS2012更新3)和.NET 4.5.1 (TFS2013)的msbuild,所有这些都在ngen中产生了相同的错误。它只是Visual Studio2010 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)发布于 2014-02-07 15:17:27
您可以使用Fuslogvw.exe (程序集绑定日志查看器)来查看ngen试图加载的程序集。这可能会提供一个线索。您可能希望为您提到的两种情况(msbuild和VS)捕获绑定日志,然后对它们进行比较。我猜mbuild引入了一些NGEN不能使用的依赖项。
当你说运行时行为是一样的,你的意思是应用程序正在按照它应该的方式工作?那么它必须使用IL而不是Native Images运行。同样,您可以使用Fulogvw检查这一点。
https://stackoverflow.com/questions/19791111
复制相似问题