Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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# 签署应用程序时System.IO.FileLoadException_C#_Wpf_Mvvm - Fatal编程技术网

C# 签署应用程序时System.IO.FileLoadException

C# 签署应用程序时System.IO.FileLoadException,c#,wpf,mvvm,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 depende

我有一个遵循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"
它总是在寻找一个比我实际运行的版本落后1的版本

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

视图:


有没有可能你正在尝试使用?例如,通过设置或修改XAML的生成代码

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

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

上面的URI具有全名和版本。而如果没有强命名引用,则uri更像:

System.Uri resourceLocater = new System.Uri("/T_Signing;component/testcontrol.xaml", System.UriKind.Relative);
编辑:

您是否使用ProcessMonitor查看Visual Studio从何处加载V3.0.5917.24348?VisualStudio需要v3.0.5920.15596,因此必须将该DLL放在预期的位置

编辑2:

你能像这样在你的配置文件中加入一个绑定重定向吗


原件:

出现错误的一个原因是:

无法加载文件或程序集“MyApplication,Version=3.0.5917.24348,Culture=neutral,PublicKeyToken=XXXXXXXXXX”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配

当程序集已签名且对它的引用的特定版本属性设置为True时,将导致FileLoadException

检查是否将特定版本设置为False:


我发现,如果在应用程序属性(如3.0.0.0)中设置硬版本,则不会出现错误。但是,当我有3.0版。*时,我确实收到了错误。你是如何签名的?我正在项目->属性中的签名选项卡下选中“为程序集签名”,然后选择我们的密钥文件。您如何设置版本?版本在项目属性程序集信息:3.0.*中设置,因此版本由VSSystem.Uri resourceLocater=new System.Uri生成(“/MyApplication;component/view/System/systeminformationview.xaml”,System.UriKind.Relative);我所拥有的是不是意味着它们没有很强的名称?那么我该如何解决这个问题呢?@user1336827在你的情况下,名为strong的就不好了。您的引用没有公钥这一事实意味着上述答案可能不适用于您。您知道项目是否有任何预构建步骤吗?没有预构建或后构建事件。该解决方案有4个项目,但是该项目没有引用任何其他项目,也没有任何其他项目引用它。我不认为这会有什么影响。@user1336827你能在一个独立的项目中复制吗?(通过将一些文件复制到一个空项目)?可能是您的项目中的某个内容以某种方式进入其中。@user1336827如果它没有在清理和重建中复制,是否可能导致问题的项目引用了它自己(例如,它自己的上一版本)?我在项目中没有引用该项目。。。MyApplication是正在运行的应用程序。它还抱怨它无法加载自己,因为版本不匹配。哦,值得一提的是,你能将一个基本解决方案上传到tempsend.com网站供我复制吗?不幸的是,我无法用测试应用程序一致地复制它。通过创建一个控件,向引用为MyApplication的控件添加一个图像,我可以间歇性地使其发生;组件/Images/Image.jpg,然后对应用程序进行签名。第一次生成将失败,然后似乎运行正常。您是否可以执行ProcessMonitor跟踪(FileMon日志)来验证DLL是否从正确的位置加载?
*** 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.
System.Uri resourceLocater = new System.Uri("/T_Signing;V1.0.0.0;76005ee8ffcf5f2d;component/testcontrol.xaml", System.UriKind.Relative);
System.Uri resourceLocater = new System.Uri("/T_Signing;component/testcontrol.xaml", System.UriKind.Relative);
<dependentAssembly>
 <assemblyIdentity name="xxxxxx" publicKeyToken="121fae78165ba3d4"/>
 <bindingRedirect oldVersion="3.0.5920.15596" newVersion="3.0.5917.24348"/>
</dependentAssembly>