Elmah MySql Nuget Package Issue 'Could not load file or assembly' - c#

I'm trying to add Elmah to my MVC3 project. After installing via Nuget, when I try to access elmah (via localhost:port/elmah.axd), I get an error containing this:
Could not load file or assembly 'MySql.Data, Version=6.1.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
I've removed the mysql.data dll and added my own copy (version 6.4.4.0 - the documentation says you can override the dll provided with a newer version), but this error remains. Has anyone else encountered this?

My solution was to add this to my web.config:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity
name="MySql.Data"
publicKeyToken="c5687fc88969c44d"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.4.0" newVersion="6.4.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
This basically says to the compiler that whenever something requests a version of the MySql.Data assembly that's between versions 0.0.0.0 and 6.4.4.0, it should instead be supplied with the version 6.4.4.0 assembly instead.

Related

Could not load file or assembly 'System.Buffers, Version=4.0.2.0...'

I'm getting the following exception when trying to call GetDatabase method of the MongoClient class after adding a new configuration using VS config. manager:
Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I installed the latest System.Buffer nuget package v4.5.1, created dependentAssembly in my app.config and Reference in my .csproj file, but I still have the same issue. For some reason it tries to reference System.Buffer with v4.0.2. Has anyone had a similar error and how did you solve it?
Could not load file or assembly 'System.Buffers, Version=4.0.2.0…'
Solution
1) use CMD(run as Administrator ) and type
cd xxxx(xxxx\packages\System.Buffers.4.5.1\lib\netstandard2.0))
run
gacutil /i System.Buffers.dll
Then, when you finish it, please run update-package -reinstall under package manager console to reinstall the package.
2) you can try to change Version=4.0.2.0 to Version=4.0.3.0 in csproj file.
Besides, there is a similar issue you can refer to.
The easiest way is to use Nuget package manager, downgrade system.buffers to any lower version, and then upgrade it to the latest again.
In my case, I had to add the assembly reference in the web.config that was already published in the Azure App Service, inside the <configuration></configuration> tag:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I ran into this issue when adding the Azure.Storage.Blobs package to a Class Library where I was attempting to create a blob uploader client. When I added the package, it created an app.config with the correct binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
The issue, however, is that this binding redirect needs to live in the app.config of the application, not the class library: Can a class library have an App.config file?
So, adding the binding redirect is the correct way to solve this issue. Just make sure the binding redirect is specified in the calling web/console/etc app.
Another solution: just remove references to the assembly in the Web.config files of the projects generating the exception.
The references can look like:
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly>
I ran into a similar issue, tried all the steps above. In the end, another project had an older version of the same library. Too many projects in the solution, the other reference was scrolled out of view.

Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0' or one of its dependencies

Recently I have started using SSMS 2017 (v17.5). In my MVC application, I am getting Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. error. Only thing changed in my application is Microsoft.SqlServer.Types version which is 14.0.0.0 now. Previously, it was 12.0.0.0.
Following are different options I have tried so far based on my research (this includes another stackoverflow articles + google) but I am getting same error.
Add <dependentAssembly> in app.config
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
Adding following line in Global.asax.cs in Application_Start method.
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
Installing Microsoft.SqlServer.Types using NuGet.
PM> Install-Package Microsoft.SqlServer.Types
Searched for 10.0.0.0 referance in entire project but didn't find any referance.
I do have Microsoft System CLR Types for SQL Server installed for 2012, 2014, 2016 and 2017.
What am I missing here?
After spending almost a day, I was able to fix this issue. From my question above, option-1 worked for me. Only tweak was to add that in web.config instead of app.config. Hope this help someone else.
Code: web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Microsoft.SqlServer.Types -Version 14.0.314.76 is the current version. try changing your version number. Second, check your .csproj file, Application also maintains its dependencies in .csproj file
For a net library project that have the same error, I go to NuGet packages and install this library:
Microsoft.SqlServer.Types
and its works.

Could not load file or assembly - reflection insist loading an old version

I got the following error when running a unit test in Visual Studio (2013).
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Newtonsoft.Json is a DLL that I referenced. But interestingly I referenced to Newtonsoft.Json 7.0 in all places. I was confused why reflection insisted loading an older version 6.0.
Any hint on where could I start to investigate?
Thanks,
I would check your web.config file to see if there is something that is referencing the old version.
You can also try this adding this in the web.config to ensure the correct version is used. I would put this in just after the <system.web> tag
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Conflict of version for NLog

I am trying to compile my project named MyAssembly, and when including other assembly named ExternalAssembly that also references NLog, I get the following error :
Assembly ExternalAssembly, Version=1.0.0.0 uses NLog, Version=2.1.0.0 which has a higher version than referenced assembly NLog, Version=2.0.0.0
I went to my app config and added the following entry:
<?xml version="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120E14C03D0593C" culture="neutral"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="2.1.0.0"/>
</dependentAssembly>
...
But I still get the same error.
Any ideas about why it is not working, and how to fix this error?
To solve this issue I had to upgrade the NLog reference of my project to match the one of the third party (2.1.0.0).

How to solve could not load assembly using Sitecore7 and Glassmapper

For a project I'm using Sitecore version 7 and the latest version of GlassMapper. It's an ASP.net MVC3 project. When I try to add a new controller, an error occured:
Microsoft Visual Studio
Could not load file or assembly 'Sitecore.Kernel, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
Can GlassMapper work with Sitecore version 7.0? Does anyone know how to solve this problem? I don't like it if I need to downgrade to Sitecore version 6.6.
Thanks a lot.
Jordy
It is possible that one of the other assemblies is referencing sitecore 6 dll. You could override it in your configuration to use sitecore 7 like this.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Sitecore.Kernel" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="5.0.0.0-6.6.0.0" newVersion="7.1.0.0" />
</dependentAssembly>
<dependentAssembly>
</runtime>
hope this helps.

Categories