草庐IT

c# - FileLoadException 在 InitializeComponent 或 x :Class=

coder 2024-05-28 原文

我在 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/

有关c# - FileLoadException 在 InitializeComponent 或 x :Class=的更多相关文章

  1. c# - 如何在 ruby​​ 中调用 C# dll? - 2

    如何在ruby​​中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL

  2. C# 到 Ruby sha1 base64 编码 - 2

    我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha

  3. 基于C#实现简易绘图工具【100010177】 - 2

    C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.

  4. Ruby - 如何处理子类意外覆盖父类(super class)私有(private)字段的问题? - 2

    假设您编写了一个类Sup,我决定将其扩展为SubSup。我不仅需要了解你发布的接口(interface),还需要了解你的私有(private)字段。见证这次失败:classSupdefinitialize@privateField="fromsup"enddefgetXreturn@privateFieldendendclassSub问题是,解决这个问题的正确方法是什么?看起来子类应该能够使用它想要的任何字段而不会弄乱父类(superclass)。编辑:equivalentexampleinJava返回"fromSup",这也是它应该产生的答案。 最佳答案

  5. ruby - 无法理解 `puts{}.class` 和 `puts({}.class)` 之间的区别 - 2

    由于匿名block和散列block看起来大致相同。我正在玩它。我做了一些严肃的观察,如下所示:{}.class#=>Hash好的,这很酷。空block被视为Hash。print{}.class#=>NilClassputs{}.class#=>NilClass为什么上面的代码和NilClass一样,下面的代码又显示了Hash?puts({}.class)#Hash#=>nilprint({}.class)#Hash=>nil谁能帮我理解上面发生了什么?我完全不同意@Lindydancer的观点你如何解释下面几行:print{}.class#NilClassprint[].class#A

  6. ruby - 使用 Class.new 时访问外部范围 - 2

    是否有可能以某种方式访问​​Class.new范围内的a?a=5Class.new{defb;aend}.new.b#NameError:undefinedlocalvariableormethod`a'for#:0x007fa8b15e9af0>#:in`b' 最佳答案 即使@MarekLipka的回答是正确的——改变变量范围总是有风险的。这是可行的,因为每个block都带有创建它的上下文,因此您的局部变量a突然变得不那么局部了——它变成了一个“隐藏的”全局变量:a=5object=Class.new{define_method(

  7. ruby - 模块中的 instance_eval 与 class_eval - 2

    classFooincludeModule.new{class_eval"deflab;puts'm'end"}deflabsuperputs'c'endendFoo.new.lab#=>mc======================================================================classFooincludeModule.new{instance_eval"deflab;puts'm'end"}deflabsuperputs'c'endend注意这里我把class_eval改成了instance_evalFoo.new.labresc

  8. ruby-on-rails - Rails - 父类(super class)不匹配 - 2

    玩转Rails和Controller继承。我创建了一个名为AdminController的Controller,其中一个名为admin_user_controller的子类位于/app/controllers/admin/admin_user_controller.rb这是我的routes.rbnamespace:admindoresources:admin_user#Havetheadminmanagethemhere.endapp/controllers/admin/admin_user_controller.rbclassAdminUserController应用程序/Contr

  9. ruby-on-rails - ApplicationController :Class 的未定义方法 `caches_action' - 2

    我正在尝试升级到Rails4beta1,但遇到了一些问题。简而言之,这就是我的应用程序Controller的样子。classApplicationControllercaches_action在Rails4中移到了它自己的gem中,因此包含gem应该可以解决问题。gem"actionpack-action_caching",github:"rails/actionpack-action_caching"但是当我运行我的请求规范或在浏览器中访问该应用程序时,我收到此错误。app/controllers/application_controller.rb:3:in`':undefinedm

  10. ruby - 为什么在 Ruby 中一切都是 Class 的实例? - 2

    这个问题在这里已经有了答案:Rubymetaclassconfusion(4个答案)关闭7年前。我对Ruby对象模型不太了解。首先,Ruby中的一切都是Class的实例吗??这些都产生true:pObject.instance_of?(Class)pClass.instance_of?(Class)pModule.instance_of?(Class)pBasicObject.instance_of?(Class)classHello;endpHello.instance_of?(Class)我不太明白这怎么可能,如果Object是Class的父类(superclass),它怎么可能都

随机推荐