13

InitializeComponent我在-method处得到一个文件加载器异常(第一次机会),或者调试器在x:Class多个 WPF 用户控件的 xaml-root 的属性处中断。尽管异常会大大减慢导航速度,但一切正常。

这是异常消息:

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

这是融合日志:

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.

我的项目结构有一个引用模块项目(发生异常)的根项目。模块项目本身引用了作为上述探测“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.

目前发生异常时,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

找到的版本是:

LOG: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18466, Culture=neutral, PublicKeyToken=45069ab0c15881ce

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

4

2 回答 2

7
   Version=0.1.5577.18122

这个自动生成的版本号说明了一个故事,版本号的最后两部分不是任意的。它们基于装配体的构建日期和时间。内部版本号是根据自 2000 年 1 月 1 日以来的天数生成的。修订号是自午夜以来的秒数 *2,没有夏令时校正。

所以我们知道的事实是 18122 组件是在 3 月 30 日下午 2:12:34 建立的。然后它在下午 2 点 12 分 36 秒 2 秒后再次构建。在它被用作参考程序集来构建另一个项目之后,这让 CLR 吐了口水。

这不应该发生,一个项目只能在一个构建会话中构建一次。找出发生这种情况的原因需要深入研究 MSBuild 跟踪。您可以使用工具 + 选项、项目和解决方案、构建和运行生成所需的内容。将“MSBuild 项目构建输出详细程度”设置更改为详细。MSBuild 现在变得非常健谈,并告诉您它决定构建项目的原因。如果您在试图解码其输出的树林中迷路(有很多),则将其复制/粘贴到粘贴箱中并在您的问题中链接到它。

对于这样的事故,没有太多很好的解释。较旧的 VS 版本很容易意外地在项目之间创建循环依赖关系。您可以使用 Build + Clean 将其清除。重建解决方案现在失败,并告诉您哪个参考程序集是麻烦制造者。但是,您使用的是 .NET 4,因此至少是 VS2010。所以不是一个很好的领先优势,微软增加了更多的检查来防止这种情况在没有警告的情况下发生。不确定它是否在所有情况下都可靠,例如,如果您不单独依赖 MSBuild,它可能会被愚弄。在具有“持续集成”功能的构建服务器上并不少见。

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

于 2015-04-09T09:30:18.303 回答
1

建议一

是否存在导致加载旧版本 dll 的循环引用?(这被证明不是重点,但由于历史原因我已经离开了)。 与此答案有关

建议二

您可以尝试创建发布者政策吗?这是一个需要添加到 app.config 文件中的示例。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Company.Solution.UserInterface"
                        publicKeyToken="45069ab0c15881ce"
                        culture="en-us" />
      <!-- Redirecting to version 0.1.5568.25577 of the assembly. -->
      <bindingRedirect oldVersion="0.0.0.0-0.1.5568.25577"
                      newVersion="0.1.5568.25577"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

这里有更详细的解释

建议 3

用于签署程序集的密钥是否有任何变化?

建议 4

作为我最初建议的轻微改编。您已声明有 3 个项目引用了 Company.Solution.UserInterface。您能否确认所有 3 个项目都引用了该程序集的相同版本?

于 2015-04-09T07:51:15.783 回答