FileLoadException - Could not load file or assembly - c#

All of a suddon, I'm getting a FileLoadException when getting an instance of a class from Ninject.
The exact exception is the following:
System.IO.FileLoadException: "Could not load file or assembly 'Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
When reading the error message, it seems quite clear that it tries to load an assembly of Quartz with version 2.3.3.0 but the specified version is another... but I don't get why it even loads version 2.3.3.0.
I searched the whole solution (inclusive the .csproj) for Quartz references and every reference states v1.0.1.2.
I've searched the path on the file system for Quartz.dlls but could only find dlls of version 1.0.1.2 so I don't understand why it tries to load 2.3.3.0.
Do you know of any steps I could try to solve this exception?
Thanks in advance

Check the class library that includes Quartz. Make sure that the platform version is consistent. You can do this by right clicking on the project file and selecting properties. Then check the assembly version in the first/top most tab.
Whatever platform version you have in that class library should be consistent with the other projects in the solution.

This happens when you install some other nuget package (like Quartz.Unity) which depends on Quartz. While installing that other package if you select 'lowest' option for dependency then it would set Quartz 2.3.3.0 as dependency. However, you have Quartz 2.4.1 installed in your package. So you get the error.
Solution: While installing that other package select 'highest' option for dependency if you have highest version installed in your project.

Related

Is there a way to create a NuGet package that allows for its dependencies to be upgraded?

Last year, I created a NuGet package that contained a single DLL and has a single dependency on the DocumentFormat.OpenXml NuGet project version 2.5.0. Since then, the DocumentFormat.OpenXml has been upgraded. If someone tries to upgrade DocumentFormat.OpenXml to the latest version, my code will throw the following error:
Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.5.5631.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not match
the assembly reference. (Exception from HRESULT: 0x80131040)
I've tried setting my project's AutoGenerateBindingRedirects to true and setting the dll's "Specific Version" to false, but neither helps the user of the my NuGet package. Yes, they could put in a bindingRedirect in their configuration file and manually tell it to use something else or run the PM command (Get-Project –All | Add-BindingRedirect), but I was trying to find a way of automating this so that they user doesn't have to deal with it.
If you go to the NuGet site, they invest a lot of time talking about how to adjust your NuSpec file to allow for different versions, but I cannot find any guidance on how to actually make your code accept multiple versions OR how to create the bindingRedirect for the user automatically.

How to resolve "The located assembly's manifest definition does not match the assembly reference." error?

I downloaded source code for pdfiumviewer from git hub. I made changes to one of the projects in that solution.Then I added that project to my application and added reference of that project to one my application's project.I had to uncheck the Signing option for the PDfiumViewer project, as some of the dll in that project are unsigned.I am able to build the application successfully.But at run time when I create an object of one of the class of PDfiumviewer project.It gives me the following error:
Could not load file or assembly 'PdfiumViewer, Version=2.11.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
The version number of the assembly is correct.So, why am I getting this error?
The problem was that I had added reference of old unmodifed PdfiumViewer dll to another project.Hence, there was conflict between the two dlls (old and customized) at runtime.I removed the old dll reference and it worked.
Ive also encountered this issue, my scenario was thou that I had to add a reference from another solution into my project removing the reference was not an option - what worked for me was reinstall SQLclient from nuget package managerer on both solution. Hopes it helo someone else
The issue here is that you have a library that references v2.11.0.0 of the Pdfium library. This library could be an assembly that you built earlier, or another assembly that came from Pdfium that references this version of the library. When you built your version of the library you probably didn't use this same version number, and it wouldn't have been strong named correctly. To fix this, you can add an assembly binding redirect in your applications configuration file to redirect the offending library to your custom built one.
I wrote a program to fix this issue automatically: https://github.com/BackTrak/DependencyFixup/releases/tag/1.0.0.0
I know this question is old, but hopefully this helps out others!

Getting exceptions when running basic orleans application

I'm involved in a IoT project and considering orleans as a platform. I tried to do the basic tutorial here:
http://dotnet.github.io/orleans/Step-by-step-Tutorials/Minimal-Orleans-Application
It seems to be working but I'm getting the following exceptions in the console which would be nice to get rid of:
Could not load file or assembly 'OrleansCodeGenerator' or one of its
dependencies. The system cannot find the file specified. Exception =
System.IO.FileNotFoundException: Could not load file or assembly
'OrleansCodeGenerator' or one of its dependencies. The system cannot
find the file specified.
Could not load file or assembly
'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or
one of its dependencies. The system cannot find the file specified.
I'm using orleans version 1.1.0
This is a know issue on the template packages. Could you please add the Nuget Microsoft.Extensions.DependencyInjection.Abstractions version 1.0.0-rc1-final on the Silo host Project? For the other exception, looks like are missing the OrleansCodegenerator package. Could you please ensure that .Server nuget is on Silo Host, .Client on Client/FrontEnd and .Core in Interfaces/Grain project? I think it will work otherwise, feel free to open an issue on https://github.com/dotnet/orleans and we will have a look.
More info
The reason this dependency is not added by default as a OrleansCodegenerator dependency, is that this package is not published as a stable package (it is marked as pre-release) and we can't have pre-release packages on Orleans packages otherwise, we would must release Orleans packages as -pre packages. As soon as this package is published as release we are going to update Orleans packages to contain it.

Watin Exception [duplicate]

I am getting the following WatiN error:
Unhandled Exception: System.IO.FileLoadException: Could not load file
or assembl y 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=db7cfd3acb5 ad44e' or one of its dependencies. The
located assembly's manifest definition do es not match the assembly
reference. (Exception from HRESULT: 0x80131040) File name:
'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=db
I copied the shDocvw.dll from System32 to the bin directory but still it is giving me the same problems.
If you've installed and referenced WatiN using NuGet in VS2010, you should already have the correct references, so they don't need to be removed and re-added. But you will still need to change the "Embed Interop Types" setting to False on the Interop.SHDocVw reference.
UPDATE: This answer was written before Nuget was released and applies only if you are NOT using Nuget to manage your dependencies. If you are using Nuget see the answer by #Nick Jones
I just had this issue today. You need to download the latest version of WatiN (I'm using 2.0.10.928) and reference the signed Interop.SHDocVw.dll that is provided by WatiN.
Try the follwoing:
Remove all other References to Interop.SHDocVw.dll
Right Click your solution and select 'Clean Solution'
Reference the Interop.SHDocVw.dll that is provided by WatiN
Build your solution.
Hope this helps.
UPDATE: Nick Jones is correct. This should not be an issue if you are using NuGet....but I was also getting this message when using MvcContrib.Mvc3.TestHelper-ci. At first glance it seems like the '-ci' packages is the way to go but I decided to use the MvcContrib.WatiN package for two reasons.
1) I don't get the "Could not load file or assembly" error message
2) The MvcContrib.Mvc3.TestHelper-ci is using an old version of WatiN.Core.dll (1.3.0.4000) where as the MvcContrib.WatiN package is using a newer version (2.0.0.99)
Check out the Properties of the Reference "Interop.SHDocVw.dll". Change the "Embed Interop Types" to False.
The problem is that it is not copying the dll file in your bin folder. But after this setting, it will do it properly.
I had the same error, and now its working fine.

Missing Dependency: Castle.DynamicProxy2 after install LINQtoExecl from NuGet

I recently added the package LinqToExcel to my .net 4 WPF project and now when entering the designer I am presented with the following error:
System.IO.FileNotFoundException
Could not load file or assembly 'Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The system cannot find the file specified.
LinqToExcel only has one dependency - log4net, which it installed as part of the NuGet process. Both are referenced and set to Copy Local. I'm not sure where the reference to Castle is coming from or how to go about fixing it.
Does anyone have any suggestions?

Categories

Resources