FileLoadException在InitializeComponent或x:Class =

Con*_*ole 12 c# wpf assemblybinding probing

我在InitializeComponent-method 获得了文件加载器异常(第一次机会),或者调试器在x:Class多个WPF用户控件的xaml-root属性处断开.尽管异常减慢了导航的速度,但一切都运行良好.

这是异常消息:

无法加载文件或程序集'Company.Solution.UserInterface,Version = 0.1.5568.25577,Culture = neutral,PublicKeyToken = 45069ab0c15881ce'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)

这是Fusion日志:

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  D:\Development\Product\Main\src\Company.Product \bin\Debug\Product.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Company.Product .UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce
(Fully-specified)
LOG: Appbase = file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.     
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Development\Product \Main\src\Company.Product \bin\Debug\Product .vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Company.Product .UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce
LOG: Attempting download of new URL file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/Company.Product.UserInterface.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Run Code Online (Sandbox Code Playgroud)

我的项目结构有一个根项目,它引用一个模块项目(发生异常).模块项目本身引用了上述探测"Company.Product.UserInterface.dll"的目标项目,该项目包含一些资源/控件/样式/基元/转换器等.

我怎么能摆脱FileLoadExceptions

另一个更完整的Fusion-log:

=== Pre-bind state information ===
LOG: DisplayName = Company.Product.UserInterface, Version=0.1.5577.18122,      Culture=neutral, PublicKeyToken=45069ab0c15881ce
(Fully-specified)
LOG: Appbase = file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Product.vshost.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Development\Product\Main\src\Company.Product\bin\Debug\Product.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Company.Product.UserInterface, Version=0.1.5577.18122, Culture=neutral, PublicKeyToken=45069ab0c15881ce
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Development/Product/Main/src/Company.Product/bin/Debug/Company.Product.UserInterface.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\Development\Product\Main\src\Company.Product\bin\Debug\Company.Product.UserInterface.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18123, Culture=neutral, PublicKeyToken=45069ab0c15881ce
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Run Code Online (Sandbox Code Playgroud)

在发生异常时,引用的SolutionExplorer中的程序集版本为0.1.5577.18123(在所有引用..UserInterface.dll的解决方案中.我不知道谁查找0.1.5577.18122,此版本从未存在过)

如果我运行一个新的重建,我得到相同的错误,Fusion寻找(我从来没有这个版本号):

LOG: Post-policy reference: Company.Product.UserInterface, Version=0.1.5577.18465, Culture=neutral, PublicKeyToken=45069ab0c15881ce
Run Code Online (Sandbox Code Playgroud)

找到的版本是:

LOG: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18466, Culture=neutral, PublicKeyToken=45069ab0c15881ce
Run Code Online (Sandbox Code Playgroud)

Visual Studio版本是2013 Ultimate,该项目基于.net4.5构建,并且构建版本在构建过程中自动生成.我将构建日志上传到tinyupload,因为它太大了.可以在pastebin上找到完整的Fusion-log .

Han*_*ant 7

   Version=0.1.5577.18122
Run Code Online (Sandbox Code Playgroud)

这个自动生成的版本号告诉了一个故事,版本号的最后两部分不是任意的.它们基于组件构建的日期和时间.内部版本号是从2000年1月1日以来的天数生成的.修订号是自午夜以来没有夏令时修正的秒数*2.

所以我们知道的事实是18122年的集会建于3月30日下午2:12:34.然后它再次建成,2秒后在下午2:12:36.在它被用作构建另一个项目的参考组件之后,这使得CLR吐出子弹.

这应该不会发生,一个项目必须在一个建立会话一次建成.找出发生这种情况的原因需要深入研究MSBuild跟踪.您可以使用工具+选项,项目和解决方案,构建和运行生成所需的工具.将"MSBuild项目构建输出详细程度"设置更改为"详细".MSBuild现在非常健谈,并告诉你为什么决定建立一个项目.如果你在树林里迷路试图解码它的输出(有很多),然后将它复制/粘贴到一个粘贴盒中并在你的问题中链接到它.

对于像这样的事故,没有太多很好的解释.较旧的VS版本很容易在项目之间意外创建循环依赖.您可以使用Build + Clean刷新它.现在重建解决方案失败并告诉您哪个参考组件是麻烦制造者.但是你使用的是.NET 4,至少VS2010.所以不是一个出色的领导,微软增加了更多的检查,以防止这种情况发生,没有警告.不确定它是否在所有情况下都是可靠的,如果你不依赖于MSBuild,它可能会被愚弄.在具有"持续集成"功能的构建服务器上并不罕见.

我们需要构建跟踪来为您提供可靠的诊断.