gpt4 book ai didi

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

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

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

在任何 View 中,如果我在初始化 View 时在应用程序中引用另一个 namespace ,我会收到错误:

"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 的版本。

如果我从 View 中删除对其他命名空间的引用,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-->

如果我删除这些引用,并将我的转换器和行为移动到另一个 DLL 中,然后通过该 DLL 引用它们,则没有问题。错误消失了。此外,如果我不签署应用程序,我不会收到错误。我真的不想在不同的 DLL 中引用这些东西,看起来这应该可以正常工作。在创建所有 View 时,它还花费了大约 30 秒来抛出所有这些错误,因此我对性能造成了影响。我不明白为什么该应用程序要尝试加载自身,以及为什么它要尝试加载其自身的旧版本。无论我构建多少次,错误总是落后 1 个版本。

融合日志:

*** 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.

最佳答案

编辑:

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

编辑 2:

Can you put in a binding redirect in your config file like this?

<dependentAssembly>
<assemblyIdentity name="xxxxxx" publicKeyToken="121fae78165ba3d4"/>
<bindingRedirect oldVersion="3.0.5920.15596" newVersion="3.0.5917.24348"/>
</dependentAssembly>

引用:.Net picking wrong referenced assembly version

原文:

您可能会收到错误的一个原因:

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.

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

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

enter image description here

关于c# - 签署应用程序时出现 System.IO.FileLoadException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35995580/

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