Could not load file or assembly 'System.Web.Mvc' . How to use the correct reference?

Error was caused due to incorrect binding. I changed:

<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>

to

  <dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.0.0.0" />

and it works now.


Well, it's the version binding concern, and for the users getting into this now as in 2019, with say, VS 2017, (as I ran into) and as the OP mentioned :

How do I upgrade the version of System.Web.Mvc to point to the correct assembly?

Always let nuget package manager do it for you, to make the correct versions installed according to your project .NET version etc.

Since, I reached here searching for my issue :

Could not load file or assembly 'System.Web.Mvc, Version=5.2.4.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)

and got the indication of version binding concern, I did the following: Nuget Mvc Update

and it worked quite smoothly thereafter.

@Ahmed, Thanks for pointing to the right direction, though


In my case i solved by changing the PageControls and assemblyBinding elements on config to match the current version of `System.Web.Mvc, wich is 5.2.4.0

PageControls

At the PageControls section replace the version in all occurrences of assembly "System.Web.Mvc", for your current version.:

 <pages controlRenderingCompatibilityVersion="4.0" validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc"/>
  </controls>

assemblyBinding

At the assemblyBindingelement map all previous versions of the assembly to the current version, like this:

 <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
  </dependentAssembly>

This element it is used by any package the references an old version.

How to check the current version of 'System.Web.Mvc'

You current version of System.Web.Mvc can be seen in properties tab, selecting the assembly from the project references, like this:

enter image description here

Note: I am answering an 2 years old question, so reasons for this error occur now may be different