0
votes

I get the following error message when trying to launch my asp.net application:

Error 1 Assembly 'MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

What does this message mean? What is the difference between the used assembly and the referenced one?

When looking at System.Web.Http assembly's properties (via Solution Explorer -> My Project -> References -> System.Web.Http) I can see 5.2.3.0.

There is a lot of questions/answers on SO related to this kind of error but I can't find one really explaining what's going on.

1

1 Answers

0
votes

The trick is that System.Web.Http is loaded as part of the web application initialization, long before your project reference comes to play. So by the time your project loads, it's trying to load a newer version of the same assembly into the same application domain, causing an error.

You can use an assembly binding redirect in your web.config:

<configuration>
  <runtime>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" 
      culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
  </runtime>
</configuration.