Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.FileLoadException when signing application

Tags:

c#

mvvm

wpf

I have a WPF application that follows the MVVM pattern. We recently signed the app and now I am getting a lot of first chance exceptions on startup. I have traced the problem to the following:

In any view, if I reference another namespace with in the application when the view is initialized I get the error:

"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"

Its always looking for a version that is 1 behind the version that I'm actually running.

If I remove the references to the other namespaces from the views, the InitializeComponent() does not throw the error

View:

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

If I remove these references, and move my converters and behaviors into another DLL and then reference them through the DLL there is no problem. The errors go away. Also If I don't sign the application I do not get the errors. I don't really want to have to reference these things in a different DLL, it seems like this should work fine. It also spends about 30 seconds throwing all of these errors as all of the views are created, so I am taking a hit on performance. I dont get why the application is trying to load itself, and why its trying to load an older version of itself. No matter how many times I build, the error is always 1 version behind.

Fusion Log:

*** 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.
like image 838
user1336827 Avatar asked Mar 14 '16 18:03

user1336827


1 Answers

Edit:

Did you use ProcessMonitor to see where Visual Studio is loading v 3.0.5917.24348 from? Visual Studio wants v3.0.5920.15596 so you have to put that DLL where its expected.

Edit 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>

Ref: .Net picking wrong referenced assembly version

Original:

One reason you might get the error:

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.

Is when your assembly is signed and your reference to it has the Specific Version property set to True, resulting in FileLoadException.

Check you have Specific Version set to False:

enter image description here

like image 122
Jeremy Thompson Avatar answered Oct 20 '22 10:10

Jeremy Thompson