Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN - c#

I've already been through this answer on S.O. but it really doesn't seem to solve my issue - this is not a complex multi-project web solution.. it's much smaller and doesn't really need binding redirects as there aren't multiple projects vying for the same DLL reference.
For the project in question: we own the source code, we have the Visual Studio Project files, the DLLs in question here are wholly owned and wholly known.. we have access to the history of the code in SVN.
In short, I wanted to upgrade a DLL that we once-upon-a-time would drop into another project, manually.. I want to turn it into a NuGet on our private feed. I've done this a hundred times.. no big deal.
The DLL is a fairly simple .NET 4 framework code and has no other dependencies
But when I 'nugetize' the project and then reference it in another project, it cannot be 'found' successfully at run time. I get this error when we go to invoke the class contained within it:
Could not load file or assembly 'MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
If I go into debug mode, visual studio shows this in the FusionLog property of the error intellisense:
=== Pre-bind state information ===
LOG: DisplayName = MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727
(Fully-specified)
LOG: Appbase = file:///C:/MyCorpRepository/MyCorp.AttachmentManager/Trunk/MyCorp.AttachmentManager.Tests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : MyCorp.DefaultAttachmentManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyCorpRepository\MyCorp.AttachmentManager\Trunk\MyCorp.AttachmentManager.Tests\bin\Debug\MyCorp.AttachmentManager.Tests.dll.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: MyCorp.DataAccessLayer, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e5ee1faf2523c727
LOG: Attempting download of new URL file:///C:/MyCorpRepository/MyCorp.AttachmentManager/Trunk/MyCorp.AttachmentManager.Tests/bin/Debug/MyCorp.DataAccessLayer.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
What do I need to look at to pinpoint the problem?

Related

Could not load file or assembly 'Microsoft.Data.SqlClient' in .NET standard Library

I've created a .NET standard library 2.0 which uses Microsoft.Data.SqlClient Version=1.12.20106.1. I'm referring to this library in the console application (.NET Framework 4.7.2). While making call, I'm getting the error shown below, even though I've added an assembly reference. Can anyone help please?
Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5"}
Chances are that in the full error you will see something like
The located assembly's manifest definition does not match the
assembly reference. (Exception from HRESULT: 0x80131040)
When I experience a similar problem and run a unit test in the debugger then I see this sort of thing in the unit test output Pre-bind state information
Pre-bind state information
LOG: DisplayName = Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
(Fully-specified)
LOG: Appbase = file:///C:/Dev2/MyApp/UnitTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : MyApp, Version=1.0.0.2, Culture=neutral, PublicKeyToken=c.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Dev2\myapp\UnitTests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 2.0.20168.4 redirected to 1.12.20106.1.
LOG: Post-policy reference: Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
LOG: Attempting download of new URL file:///C:/Dev2/MyApp/UnitTests/bin/Debug/Microsoft.Data.SqlClient.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
The issue is an assembly binding issue the answer here may help. Don't worry that it mentions VB6 the actual issue is independent of that.
This answer is only useful if your netstandard2.0 library has referenced Microsoft.Data.SqlClient as a NuGet package and the referred assembly is not copied over on build.
You may have to use dotnet publish to have the Microsoft.Data.SqlClient assembly copied. It's something that I stumbled upon lately and that I had to fix using a custom resolver. You shouldn't use that resolver but you should check if publishing your application and library helps the issue.

Failure to load System.runtime dll on Visual studio WebApi project

When i run the portal it gives the following error:
Could not load file or assembly 'System.Runtime, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///D:/.....
LOG: Initial PrivatePath = ....\bin
Calling assembly : System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: ....\web.config
LOG: Using host configuration file: ....\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80131040.
System.Runtime is a Microsoft package that is part of the webapi project.
Observing the Pre-bind state information it shows that the system.runtime dll is being called from System.Runtime.CompilerServices.Unsafe dll. Also the following redirect is made:
LOG: Redirect found in application configuration file: 4.0.0.0
redirected to 4.1.1.0.
The System.Runtime Package version is 4.3.0 and generates dll version 4.1.1.0.
This is my first doubt. I thing dll version should be 4.3.0.0 but inspecting with ILSpy it shows that the Assembly version attribute is 4.1.1.0
Web config redirect is correct, it redirects the call to version 4.0.0.0 to
version 4.1.1.0 as show in the Pre-bind log
The odd thing is that System.Runtime doesn't show in the references of the project. If i add it manually it gets an yellow icon (fail).
What is wrong here? What more can i check?
Found out that the problem was caused by a version conflict and not by an incompatible version as i expected.
The follow build warning exposed the conflict. Just need to double click on the warning message to fix the binding session on the web conflict.
Warning Found conflicts between different versions of the same
dependent assembly. In Visual Studio, double-click this warning (or
select it and press Enter) to fix the conflicts; otherwise, add the
following binding redirects to the "runtime" node in the application
configuration file: ...
I am not sure if Visual studio will be able to detect all build conflicts,so the absence of this warning may still be caused by the same error.

Crystal Reports keeps giving me: Could not load file or assembly

So I have a C# website that I have to work with. It uses crystal reports so I installed it (First time working with crystal reports). I came across the following error while trying to run the website
Could not load file or assembly 'CrystalDecisions.Enterprise.Framework, Version=11.5.9.1229, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
These are the logs :
=== Pre-bind state information ===
LOG: DisplayName = CrystalDecisions.Enterprise.Framework, Version=11.5.9.1229, Culture=neutral, PublicKeyToken=692fbea5521e1304
(Fully-specified)
LOG: Appbase = file:///C:/School/Vacaturesite/
LOG: Initial PrivatePath = C:\School\Vacaturesite\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\School\Vacaturesite\web.config
LOG: Using host configuration file: C:\Users\Beheerder\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: CrystalDecisions.Enterprise.Framework, Version=11.5.9.1229, Culture=neutral, PublicKeyToken=692fbea5521e1304
LOG: Attempting download of new URL file:///C:/Users/Beheerder/AppData/Local/Temp/Temporary ASP.NET Files/vs/ae77f9fe/8f0f70a0/CrystalDecisions.Enterprise.Framework.DLL.
LOG: Attempting download of new URL file:///C:/Users/Beheerder/AppData/Local/Temp/Temporary ASP.NET Files/vs/ae77f9fe/8f0f70a0/CrystalDecisions.Enterprise.Framework/CrystalDecisions.Enterprise.Framework.DLL.
LOG: Attempting download of new URL file:///C:/School/Vacaturesite/bin/CrystalDecisions.Enterprise.Framework.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
I've tried various things and searched the internet for answers but so far nothing worked.
you need to install crystal reports runtime. Follow the below thread to download http://scn.sap.com/thread/2071900
Following is more detailed list where you will get all runtime versions
http://wiki.scn.sap.com/wiki/pages/viewpage.action?original_fqdn=wiki.sdn.sap.com&pageId=56787567

The located assembly's manifest definition does not match the assembly reference C# Dll hell

I'm in dll hell here with a large project. I have a dll patch which I'm trying to put into the assembly such that I can overide the built dlls in the project. I'm adding the .dll to the StartProject and replacing the existing one, but I get the following error and I don't know why this is the case. I've tried changing the specific version to False and the runtime versions all look identical for each of the dll's. The only difference in properties between this dll and the others is the use of an option called SpecificVersion - but this is set to false anyway.
Failed processing: System.IO.FileLoadException: Could not load file or assembly
XXX.XXX.XXX, Version=X.X.X.X, Culture=neutral, PublicKeyTok
en=5353c9f66d4ed1ec' or one of its dependencies. The located assembly's manifest
definition does not match the assembly reference. (Exception from HRESULT: 0x80
131040)
File name: 'XXX.XXX.XXX, Version=X.X.X.X, Culture=neutral, P
ublicKeyToken=xxxxxxxxxxxxxxx'
at XXX.XXX.XXX.XXX.XXX.XX(.....)
I'm looking at the fuslogvw failure output for binding and I get the following. Sorry for Redacting again.
=== Pre-bind state information ===
LOG: User = X
LOG: DisplayName = DataObjects, Version=0.4.1060.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
(Fully-specified)
LOG: Appbase = file://X/lib/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Program.exe
Calling assembly : Storage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: DataObjects, Version=0.4.1060.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///X/DataObjects.DLL.
LOG: Assembly download was successful. Attempting setup of file: X\DataObjects.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: DataObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5353c9f66d4ed1ec
WRN: Comparing the assembly name resulted in the mismatch: Major Version
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.
SpecificVersion only matters when you build your project. At runtime, the CLR insists on finding an exact match. In other words, the [AssemblyVersion] of the reference assembly that was used when the project was originally built must be an exact match with the [AssemblyVersion] it finds back at runtime. A mismatch is very dangerous, causing true DLL Hell when the program tries to execute code in the assembly that substantially changed from the code it was tested against.
So if you create a patch then you must be sure that the [AssemblyVersion] attribute as declared in the AssemblyInfo.cs source code file matches the original. Do make sure that you don't let it increment automatically, using [1.0.*] is pretty popular and will always cause this runtime error.
Your assembly is also strong-named, the PublicKeyToken value must match as well. Be sure to sign it with the same private key.
Using a <bindingRedirect> element in the app.exe.config file is a way to force the CLR to accept a version mismatch.
After edit: yes, there's clearly a gross mismatch in the assembly version. The app was built with DataObjects version 0.4.1060.0 but found version 1.0.0.0

System.IO.FileNotFoundException: Could not load file or assembly 'X' or one of its dependencies when deploying the application

I'm having a strange problem with deploying an application, which references an assembly, written in managed c++.
I've created an assembly X, compiled it and referenced it in an exe file, called Starter.
Starter.exe starts normally on local mashine. However, when I copy ALL contents of the starter debug folder to a virtual mashine, and try to start it there, it crashes with following exception:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or
assembly 'X' or one of its dependencies. The specified module could not be found.
This does not make any sense to me, because X is right in the same folder as Starter.exe.
What could be causing this problem?
UPDATE
I've examined the dependencies in Reflector on the target machine, and it was able to find files for all of those.
I've also changed the configurations to x86/win32 for all projects.
UPDATE
Here are the logs from Fusion Log (location: C:\FusionLog\Default\Starter.exe\X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.HTM):
*** Assembly Binder Log Entry (6/4/2012 # 1:56:13 PM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/X.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.
LOG: Assembly is loaded in default load context.
The only errors are in C:\FusionLog\NativeImage\Starter.exe\ directory:
*** Assembly Binder Log Entry (6/4/2012 # 1:56:13 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Documents and Settings\Administrator\Desktop\tmp\k;k\Starter.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = MENKAUR-7683827\Administrator
LOG: DisplayName = BookmarkWiz.Kernel, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/Administrator/Desktop/tmp/k;k/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Starter.exe
Calling assembly : Starter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Start binding of native image X, Version=1.0.4538.22813, Culture=neutral, PublicKeyToken=null.
WRN: No matching native image found.
LOG: IL assembly loaded from C:\Documents and Settings\Administrator\Desktop\tmp\k;k\X.dll.
I cannot sign the assembly, as it references several other assemblies, which are not signed
... Could not load file or assembly 'X' or one of its dependencies
...
Most likely it fails to load another dependency.
you could try to check the dependencies with a dependency walker.
I.e: https://www.dependencywalker.com/
Also check your build configuration (x86 / 64)
Edit:
I also had this problem once when I was copying dlls in zip from a "untrusted" network share. The file was locked by Windows and the FileNotFoundException was raised.
See here: Detected DLLs that are from the internet and "blocked" by CASPOL
I had the same issue. For me it helped to remove the .vs directory in the project folder.
I resolved this problem by renaming the DLL. The DLL had been manually renamed when it was uploaded to its shared location (a version number was appended to the file name). Removing the version number from the downloaded file resolved the issue.
I also had the same issue when I tried to install a Windows service, in my case I managed to resolved the issue by removing blank spaces in the folder path to the service .exe, below is the command worked for me in a command prompt
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
Press ENTER to change working directory
InstallUtil.exe C:\MyService\Release\ReminderService.exe
Press ENTER
For me, I started the app from within windows explorer (by double clicking on it). Then it crashed immediately.
I then opened Event Viewer of windows and viewed Application and it displayed full stacktrace of error. The stacktrace showed relation with Bitmap or images. It was then turned out to be due to app icon not found

Categories