签署应用程序时出现System.IO.FileLoadException

use*_*827 12 c# wpf mvvm

我有一个遵循MVVM模式的WPF应用程序.我们最近签署了应用程序,现在我在启动时获得了很多第一次机会异常.我已将问题追溯到以下问题:

在任何视图中,如果我在初始化视图时在应用程序中引用另一个命名空间,我会收到错误:

"Could not load file or assembly 'MyApplication, Version=3.0.5917.24348, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"MyApplication, Version=3.0.5917.24348, Culture=neutral, PublicKeyToken=xxxxxxxxxxx"
Run Code Online (Sandbox Code Playgroud)

它总是在寻找一个比我实际运行的版本落后1的版本.

如果我从视图中删除对其他命名空间的引用,InitializeComponent()则不会抛出错误

视图:

<UserControl x:Class="MyApplication.View.DiagnosticsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:convert="clr-namespace:MyApplication.Converters"  <!--Causes error-->
             xmlns:behave="clr-namespace:MyApplication.Behaviors" <!--Causes error-->
             xmlns:controls="clr-namespace:MyApplication.UserControls"  <!--Causes error-->
Run Code Online (Sandbox Code Playgroud)

如果我删除这些引用,并将我的转换器和行为移动到另一个DLL,然后通过DLL引用它们没有问题.错误消失了.此外,如果我没有签署该应用程序,我不会得到错误.我真的不想在不同的DLL中引用这些东西,看起来这应该可以正常工作.当所有视图都被创建时,它也会花费大约30秒来抛出所有这些错误,所以我的性能受到了冲击.我不知道为什么应用程序试图加载自己,以及为什么它试图加载自己的旧版本.无论我构建多少次,错误始终是1版本.

Fusion日志:

*** Assembly Binder Log Entry  (3/17/2016 @ 10:30:11 AM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = MyApplication, Version=3.0.5920.15594, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx
 (Fully-specified)
LOG: Appbase = file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApplication.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: C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.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: MyApplication, Version=3.0.5920.15594, Culture=neutral, PublicKeyToken=7b0591cb18d2a932
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/bin/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/bin/MyApplication/MyApplication.DLL.
LOG: Attempting download of new URL file:///C:/tfs/Development/dev-feature/src/MyApplication/bin/Debug/MyApplication.EXE.
LOG: Assembly download was successful. Attempting setup of file: C:\tfs\Development\dev-feature\src\MyApplication\bin\Debug\MyApplication.exe
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyApplication, Version=3.0.5920.15596, Culture=neutral, PublicKeyToken=7b0591cb18d2a932
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)

Fri*_*Guy 0

您是否可能尝试在 XAML 中使用强名称 URI 引用?例如,通过设置AssemblyPublicKeyToken项目文件的属性或修改 XAML 生成的代码隐藏?

如果您的 XAML 引用使用强名称并且您使用不断变化的版本,那么您的 XAML 最终可能会使用项目的先前版本,因为引用是之前生成的在构建完成之前的(并且设置新版本) )。

要进行检查,请在目录下找到为 XAML 生成的内容obj并检查 Uris(例如~\obj\Debug\TestControl.g.i.cs):

System.Uri resourceLocater = new System.Uri("/T_Signing;V1.0.0.0;76005ee8ffcf5f2d;component/testcontrol.xaml", System.UriKind.Relative);
Run Code Online (Sandbox Code Playgroud)

URI 上方有完整名称和版本。然而,如果您没有强命名引用,则 uri 会更像:

System.Uri resourceLocater = new System.Uri("/T_Signing;component/testcontrol.xaml", System.UriKind.Relative);
Run Code Online (Sandbox Code Playgroud)