Could not load file or assembly 'Microsoft.Data.Edm'
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-184.108.40.206" newVersion="220.127.116.11" /> </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.
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=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.Data.Services.Client references Microsoft.Data.Edm, Version=22.214.171.124, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.WindowsAzure.Storage references Microsoft.Data.Edm, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Possible conflicts for Microsoft.Data.OData: Microsoft.Data.Services.Client references Microsoft.Data.OData, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.WindowsAzure.Storage references Microsoft.Data.OData, Version=184.108.40.206, 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.
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.
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:
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.
Here's few things you can try:
- Check your Post Build event to make sure no Microsoft.Data.Edm.dll file is being copied manually to bin folder.
- 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.
- 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.
- Uninstall WindowsAzure.Storage and Microsoft.Data.Edm packages. Then install again and make sure you only install the stable version.
I met a similar case today, in my situation, the build always copy a old version dll to debug folder, the reason is my project isn't reference this dll directly, it ref another project which refering this dll. So when build, my project find a old version from GAC or other place. I solved it by explicit reference this dll in project from the right location. like this:
<Reference Include="Microsoft.Data.Services.Client, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Microsoft.Data.Services.Client.5.6.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath> </Reference>
I've just had this same issue on my build server and on checking the build output I noticed the following:
Copying file from "C:\Program Files (x86)\Microsoft WCF Data Services\5.6\bin.NETFramework\Microsoft.Data.Edm.dll" to "bin\Microsoft.Data.Edm.dll".
Seems that there is something installed on the build server that is not on my machine, so I need to track that down.
It's probably may be problem of virtual path on IIS (I think, this assembly loaded first on application start).
I got same problem when start two project from different locations on disk but with same virtual paths.
Resolution is delete this path from IIS, reset IIS process and create virtual path again from VS.
found it !! inside your app.config file change the bindingredirect version. Make bindingredirect element refer to the version the exception complains about, and the exception will go away. explanation: Probably the app.config file and the project reference assembly got out of sync, causing the error.
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> </assemblyBinding> </runtime>
For me I had to uninstall WindowsAzure.MobileServices.Backend.Entity NuGet package which removes a lot of assemblies, including Microsoft.Data.Edm. And then I just re-installed it and miraculously, it worked!
This was in my Azure Mobile Services WebApi project, so it needed to work, and thankfully it does now.
I hope this helps.
This was successfully solved for me by closing and re-opening Visual Studio.
1) Turn Build Verbosity to Detailed 2) Search for Microsoft.Data.Edm and compare the versions of other assemblies used in the project 3) Update to the Version used in other assemblies
Solved my problem
I got this error after I had deleted my "packages" folder and re-installed the packages. I was being able to resolve the error by running "Clean Solution" and "Rebuild Solution".