Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# InitializeComponent或x:Class处的FileLoadException=_C#_Wpf_Probing_Assemblybinding - Fatal编程技术网

C# InitializeComponent或x:Class处的FileLoadException=

C# InitializeComponent或x:Class处的FileLoadException=,c#,wpf,probing,assemblybinding,C#,Wpf,Probing,Assemblybinding,我在InitializeComponent-方法中得到一个文件加载程序异常(第一次出现),或者调试器在多个WPF用户控件的xaml根的x:Class属性处中断。尽管异常会大大降低导航速度,但一切正常 这是异常消息: 无法加载文件或程序集“Company.Solution.UserInterface,Version=0.1.5568.25577,Culture=neutral,PublicKeyToken=45069ab0c15881ce”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(

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

这是异常消息:

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

这是融合日志:

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: Assembly Name is: Company.Product.UserInterface, Version=0.1.5577.18466, Culture=neutral, PublicKeyToken=45069ab0c15881ce
Visual Studio版本为2013旗舰版,项目基于.net4.5构建,程序集版本在构建过程中自动生成。 我上传了构建日志,因为它太大了。
可以找到完整的融合日志。

建议1

是否存在导致加载旧版本dll的循环引用?(事实证明这不是重点,但出于历史原因,我已经离开了)。

建议2

能否尝试创建发布者策略? 下面是一个需要添加到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个项目都引用了该程序集的同一版本

   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将其清除。现在重建解决方案失败,并告诉您哪个引用程序集是问题制造者。但是,您使用的是.NET4,所以至少是VS2010。所以这不是一个很好的线索,微软增加了更多的检查,以防止这种情况在没有警告的情况下发生。不确定它是否在所有情况下都是可靠的,例如,如果您不单独依赖MSBuild,它可能会被愚弄。在具有“持续集成”功能的构建服务器上并不少见


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

我没有循环引用,循环引用将失败,而我的应用程序确实按预期运行,它只是在创建UserControls/Pages@Console它可能不一定是循环引用,但从错误消息中可以看出,您正在加载的版本与项目期望的版本不匹配。如果您在VS中检查引用,它是否将特定版本设置为True?@Console失败,您是否尝试设置发布者策略?虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能会无效。@bit我已改进我的答案您是否检查了Fusion日志?UserInterface.dll是否仅由一个项目引用?否UserInterface由三个项目使用,然后由依赖项根目录将它们放在一起。我可以发布依赖关系图,如果这有助于判断这3个项目中有一个引用了较旧的版本?您是如何生成版本号的?我假设它是自动生成的,因为您的日志中的版本号经常更改。如果是这种情况,看起来您的一个项目可能会在UserInterface项目之前构建。我相当确定,只有当其中一个项目引用dll而不是创建dll的项目时,才可能执行此操作。我查看了MSBuild日志,但未找到任何指示问题的内容。这个项目只有g
   Version=0.1.5577.18122