Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'Microsoft.Data.Edm'

Tags:

c#

.net

dll

azure

We are using the Windows Azure Storage NuGet package version 4.1.0, this has a dependency on Microsoft.Data.OData and has added that package as well which has the Microsoft.Data.Edm dll. When we build and run the application we very occasionally get the following error:

Could not load file or assembly 'Microsoft.Data.Edm' or one of its dependencies. The
located assembly's manifest definition does not match the assembly reference. (Exception
from HRESULT: 0x80131040)

We have the following binding redirect in the web.config and also have checked and this is the only version of Microsoft.Data.Edm being referenced by any projects in the solution.

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
  </dependentAssembly>

Sometimes when I look in the bin folder I find the dll version of Microsoft.Data.Edm is v 5.6.0. I have been through all the projects and I cannot find a reference to Microsoft.Data.Edm except with the storage client and that is definitely 5.6.1.

What is the best way to try and work out where the 5.6.0 version is coming from? When we do get this error we delete the bin and obj folders and rebuild and then it works fine, the 5.6.1 version is there and everything works but eventually it happens again.

EDIT:

We have upgraded again to all the latest versions from NuGet and still no luck, I ran a tool which shows the following dependencies:

Possible conflicts for Microsoft.Data.Edm:

Microsoft.Data.OData      references Microsoft.Data.Edm, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.Data.Services.Client references Microsoft.Data.Edm, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.WindowsAzure.Storage references Microsoft.Data.Edm, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Possible conflicts for Microsoft.Data.OData:

Microsoft.Data.Services.Client references Microsoft.Data.OData, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.WindowsAzure.Storage references Microsoft.Data.OData, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

What I don't understand is we have the app binding redirects set but sometime the 2.6.0 version is copied in and sometimes the 2.6.2. Does anyone know why this would be happening, never had this problem before.

like image 820
user351711 Avatar asked Aug 07 '14 06:08

user351711


3 Answers

I had the same error message but my issue was unrelated to any Azure product. In my case, I updated OData from version 3 to 4 and it appears to me that Nuget left behind binding redirects for deprecated dll's. There were actually three in total, Microsoft.Data.Edm, Microsoft.Data.OData and System.Spatial.

My solution was to remove the deprecated binding redirects. You should also remove the old dll's sitting in your bin folder if your build process doesn't.

like image 146
Bill Avatar answered Nov 08 '22 07:11

Bill


One thing that sometimes seems to resolve this issue for members of my team is to close all instances of Visual Studio, delete the contents of the packages directory, re-open Visual Studio, and then restore packages and rebuild. This doesn't always work though.

We were able to trace the issue on one of our machines by identifying the problematic project by increasing the Visual Studio build output verbosity:

Increasing Visual Studio build output verbosity

Then, we searched the output and identified the target project that was problematic by searching for "Microsoft.Data.Edm". We noticed that it seemed to have an indirect dependency to Microsoft.Data.Edm, but we noticed that the assembly was not explicitly included as a package for that project. So, using the Nuget package console, we targeted the project and ran: Install-Package Microsoft.Data.Edm which resolved the issue.

Install Package with Nuget

like image 6
devinbost Avatar answered Nov 08 '22 07:11

devinbost


Here's few things you can try:

  1. Check your Post Build event to make sure no Microsoft.Data.Edm.dll file is being copied manually to bin folder.
  2. Make sure other packages don't have dependency to Microsoft.Data.Edm 5.6.1. Easy way to do this is by looking at your package.config files.
  3. If your code is in source control, make sure nobody check in bin folder. I am surprised by how many people don't know this basic rule.
  4. Uninstall WindowsAzure.Storage and Microsoft.Data.Edm packages. Then install again and make sure you only install the stable version.

HTH.

like image 3
stack247 Avatar answered Nov 08 '22 08:11

stack247