I have a COM object that is referenced in my project. When I build the project with target framework 4.5 everything works. However if I change the target framework to 3.5 (or 2.0), the code throws an exception when trying to instantiate the class using DLLName.exe (I presume it is an ActiveX EXE)
The following is the error (I translated it from a foreign language so it may not be exact):
System.BadImageFormatException: Could not load file or assembly 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
....
Assembly loaded from: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under file execution C:\Users\Admin\Documents\Visual Studio 2012\Projects\....t\bin\Debug\EXEname.vshost.exe
#NAME?
=== Pre-bind state information ===
LOG: User =
LOG: DisplayName = Interop.DLLname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/Admin/Documents/Visual Studio 2012/Projects/............/bin/Debug/
LOG: Initial PrivatePath = NULL
Assembly calls : EXEname, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
....
LOG: Using computer file configuration from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
....
ERR: Failed to complete assembly definition (hr = 0x8013101b).
I have tried to remove interop.DLLname.dll from the bin/obj folders, I have checked that all the projects in the build are targeting Framework 2.0
Am I missing something else?
You are getting this error because the com wrapper dll (interop.DLLname.dll) was generated for .net 4.5, obviously it can not be used in earlier versions of .net due to the different CLR version. You need to get the wrapper for .net 2.0 and reference it. Here is link on how to generate a com wrapper http://msdn.microsoft.com/en-us/library/ms404285%28v=vs.80%29.aspx
The only solution that worked in this case was to install Visual Studio 2008 and create the interop there.
Related
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?
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.
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.
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
Just starting out with C# (using VS2008) - am an experienced Java, C++, VC++, VB programmer.
I downloaded an assembly (I guess) from codescales.com; it's a dll.
In my (new) C# project, I added this dll as a Reference -- by browsing to it. I got intellisense working for it, and coded-up a simple example to test it, but everytime I hit the VS "Debug", I get the following Exception. Do I need to "register" or do something to this downloaded DLL to use it properly in my project? (VS seems to copy it to the output dir automatically on build.)
Thanks in advance,
AJ
System.IO.FileNotFoundException was
unhandled Message="Could not load
file or assembly 'CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its
dependencies. The system cannot find
the file specified."
Source="ocrTest1"
FileName="CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" FusionLog="===
Pre-bind state information ===\r\nLOG:
User = CAPTURESDK-VM\XXXXX\r\nLOG:
DisplayName = CodeScales.Http,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null\n
(Fully-specified)\r\nLOG: Appbase =
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/\r\nLOG:
Initial PrivatePath = NULL\r\nCalling
assembly : ocrTest1, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=null.\r\n===\r\nLOG:
This bind starts in default load
context.\r\nLOG: No application
configuration file found.\r\nLOG:
Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.\r\nLOG:
Policy not being applied to reference
at this time (private, custom,
partial, or location-based assembly
bind).\r\nLOG: Attempting download of
new URL file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http.DLL.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http/CodeScales.Http.DLL.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http.EXE.\r\nLOG:
Attempting download of new URL
file:///C:/Documents and
Settings/XXXXX/My Documents/Visual
Studio
2008/Projects/ocrTest1/ocrTest1/bin/Debug/CodeScales.Http/CodeScales.Http.EXE.\r\n"
There's a name mismatch, not sure how that happened. Remove the assembly reference. Rename the DLL you downloaded from CodeScales.Http.V0.14.dll to CodeScales.Http.dll. Then add the reference back.
You need to change Framework. Go to 'Properties' and the change '.Net Framework 4 Client profile' to '.Net Framework 4'.