gpt4 book ai didi

c# - FileLoadException 在 InitializeComponent 或 x :Class=

转载 作者:可可西里 更新时间:2023-11-01 08:26:20 25 4
gpt4 key购买 nike

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

这是异常信息:

Could not load file or assembly 'Company.Solution.UserInterface, Version=0.1.5568.25577, Culture=neutral, PublicKeyToken=45069ab0c15881ce' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from 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.

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

如何摆脱 FileLoadExceptions

另一个更完整的融合日志:

=== 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 构建,程序集版本在构建过程中自动生成。我上传了构建日志 to tinyupload因为它太大了。可以找到完整的 Fusion 日志 here at pastebin .

最佳答案

   Version=0.1.5577.18122

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

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

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

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

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

关于c# - FileLoadException 在 InitializeComponent 或 x :Class=,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29369879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com