asp.netnugetasp.net-optimizationweb-optimization

"The located assembly's manifest definition does not match the assembly reference" on nuget package


So I was persistently getting this error on the System.Web.Optimization package

Could not load file or assembly 'System.Web.Optimization' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


Solution

  • I finally found the solution after much trying. The key was in the Assembly load trace.

    LOG: Redirect found in application configuration file: 1.0.0.0 redirected to 1.1.0.0.
    

    Here are the steps I took to resolve the issue. It might be possible to skip some of these but this worked for me:

    It will look something like this:

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

    I don't know where this section came from in the web.config but having removed it everything seems to be working once again.