11

I added the Odata v4 package to my API, I noticed that it updated my Microsoft.AspNet.WebApi package to 5.2.3 version. But when i try to use

odata builder configuation in my WebApiConfig it showing error like 'Could not load file or assembly 'System.Web.Http, Version=5.2.2.0'.

config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

I searched this version(5.2.2) in my project but every thing is 5.2.3 and I updated all the packages too to solve this issue but failed. Copy to Local property also true for System.Web.Http dll.
Any idea?

5
  • 2
    Check your web.config. There might still be an assembly redirect in there redirecting all references to version 5.2.2.0. Commented Jul 3, 2015 at 12:42
  • Thanks, there is nothing I found in web.config, This error is occuring when I add config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)); in the webApiconfig Commented Jul 5, 2015 at 4:22
  • I have the exact same problem, did you ever find a solution for this? Commented Aug 28, 2015 at 13:44
  • @Oberheim : I updated my answer, may be that will help you. Commented Aug 29, 2015 at 15:04
  • Same problem here. Any solutions? Commented Oct 30, 2015 at 17:55

2 Answers 2

13

Visual studio solved this for me. The version conflicts are shown as warning and when I clicked it automatically added the binding redirect to my web config.

https://msdn.microsoft.com/en-us/library/2fc472t2.aspx

The binding redirect that solved my issue is,

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31BF3856AD364E35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
</assemblyBinding>
Sign up to request clarification or add additional context in comments.

1 Comment

I also have this in web.config, but I still get: "Could not load file or assembly 'System.Web.Http, Version=5.2.2.0"
0

Well this is not "real" solution but a workaround: I have changed the machine.config and replaced <runtime /> with

  <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>

so I works but if you have other web sites running...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.