2
votes

When I construct Asp.Net WebAPI using VisualStudio 2013, adding

Web API 2 OData Controller with actions using Entity FrameWork

enter image description here

after add successfully, I run the API, then the error occur:

Could not load file or assembly 'Microsoft.Data.OData, Version=5.6.0.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)

How to solve it?

1

1 Answers

5
votes

I spend long time to try and seems find the solution:

1. Open Tools > Library Package Manager > Manage Nuget Packages For solution

and serach the word "data" shows:

enter image description here

2. As the error says Microsoft.Data.OData, Version=5.6.0.0" Could not load, you can find that there's Microsoft.Data.OData installed here, name OdataLib for OData v1-3, but its version is 5.6.3 not 5.6.0.0

3. Hence now manage it and uncheck all project to uninstall it, but you'll meet the error Microsoft.AspNet.WebApi.OData 5.0.0 depends on it, hence you should first uninstalled Microsoft.AspNet.WebApi.OData 5.0.0

enter image description here

4. Then Uninstall other three packages, their id are :

.

Microsoft.Data.OData
Microsoft.Data.Edm
System.Spatial

enter image description here

5. reinstall Microsoft.Data.OData -Version 5.6.0

https://www.nuget.org/packages/Microsoft.Data.OData/5.6.0

using Package Manager Console

Install-Package Microsoft.Data.OData -Version 5.6.0

then the three orange will be reinstall with ver 5.6.0.0

enter image description here

6. reinstall Microsoft.AspNet.WebApi.OData 5.0.0

https://www.nuget.org/packages/Microsoft.AspNet.WebApi.OData/5.0.0

using Package Manager Console

Install-Package Microsoft.AspNet.WebApi.OData -Version 5.0.0

7. Then I can run the API without error