Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Elmah.MVC issue

旧时模样 提交于 2019-11-29 20:55:54
Declan

I had this exact same issue using MVC4 with Ninject built for .Net 4.5

To fix this i had to add a binding redirect to my Web.config file: (at the end of the file, just before the </configuration> tag)

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
  </dependentAssembly>
    </assemblyBinding>
  </runtime>

This forces the web server to use System.Web.Mvc 4.0.0.0 instead of an older version.

There are some procedures using to fix the issue and if the binding redirect in web.config does not solve the problem, you can try the following steps to fix it:

1) In Visual Studio Solution Explorer tree right-click References under your web project and select Manage NuGet Packages.

2) Go to Browse tab and select nuget.org as Package source.

3) Search and install the following packages: Ninject, Ninject.Web.Common and Ninject.MVC5.

It is also better to update the packages particularly Microsoft ASP.NET MVC on Updates tab of Manage NuGet Packages.

Hope this helps...

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

Check correct versions are there

Are you sure you are using ASP.NET MVC (views controllers etc)? or is your web app using ASP.NET WebAPI exclusively? If so then you should only install the ElMAH NuGet package and not Elmah.MVC.

For ASP.NET WebAPI only apps I would recommend the Emah.Contrib.WebAPI package. This package can also be installed via NuGet.

In the error page I had this:

LOG: Redirection detected in the application configuration file: 5.1.0.0 was redirected to 5.2.3.0.

So I had to change this line in the web.config to the 5.1.0.0 version and it worked!

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.1.0.0" />
    <!--<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> Older line -->
  </dependentAssembly>

I think this is due to a version problem when I downloaded the code from TFS

Hope this helps

Add below code in web.config:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.1" />
  </dependentAssembly>
</assemblyBinding>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!