简体   繁体   English

更新到版本5.2.2后,ASP.NET编译器无法加载System.Web.Mvc

[英]ASP.NET compiler cannot load System.Web.Mvc after updating to version 5.2.2

I've recently updated to MVC 5, using the instructions on this web page: 我最近使用此网页上的说明更新到MVC 5:

http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web- API-2

I'm now getting this error: 我现在收到这个错误:

Could not load file or assembly 'System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 无法加载文件或程序集'System.Web.Mvc,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 定位的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (HRESULT异常:0x80131040)

A bizarre behaviour is that sometimes the error actually says version 3.0.0.0 and sometimes 5.0.0.0. 一个奇怪的行为是,有时错误实际上说版本3.0.0.0,有时5.0.0.0。

I've done lots of searches, but cannot find anyone with the same error, just similar errors where people discuss changing versions in config files, so here are my config entries: 我已经做了很多搜索,但找不到任何有相同错误的人,只是类似的错误,人们讨论在配置文件中更改版本,所以这里是我的配置条目:

Under Views: 在视图下:

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>


  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
    <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" uiCulture="en-GB" culture="en-GB" />
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

And my site web.config file: 和我的网站web.config文件:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
        ...
      </connectionStrings>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="PreserveLoginUrl" value="true" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <authentication mode="Forms">
          <forms loginUrl="~/Account/Login" timeout="2880" />
        </authentication>
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Optimization" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
          </namespaces>
        </pages>
        <globalization requestEncoding="UTF-8" responseEncoding="UTF-8" uiCulture="en-GB" culture="en-GB" />
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
          <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
          <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
          <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
      </entityFramework>
    </configuration>

You say that you have upgraded to version 5.2.2. 您说您已升级到版本5.2.2。 Therefore you should change 因此你应该改变

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

to

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

Obviously you will need to replace all occurrences of MVC 5.0.0.0 with 5.2.2.0 . 显然,您需要将所有出现的MVC 5.0.0.0替换为5.2.2.0

You need to update the version of System.Mvc dll in your projects. 您需要在项目中更新System.Mvc dll的版本。 SportStore.Domain and SportStore.UnitTests . SportStore.DomainSportStore.UnitTests

To do it first go to one of both project and make a secondary click in project name --> after select the "Manage NuGet Packages" 要做到这一点,首先转到其中一个项目并在项目名称中进行二次单击 - >选择“管理NuGet包”后

在此输入图像描述

Inside Manage NuGetPackages you can go to "Updates" tab and select all. 在Manage NuGetPackages中,您可以转到“更新”选项卡并选择全部。 Inside this you will see all your Packages available to update. 在此内部,您将看到所有可用于更新的软件包。

Select Uptade on your MVC package. 在MVC包上选择Uptade。 In my picture I don't have it because I have full updated. 在我的照片中我没有它,因为我已经完全更新了。

在此输入图像描述

Repeat this opperation to other project and rebuild your project. 将此操作重复到其他项目并重建您的项目。

我解决了我的问题,在Views \\ web.config中获取了PublicKeyTokenVersion system.web-> Compilation-> Assemblies ,并将其替换为同一文件但在system.web.webPages.razor-> host key和root web中.cofig在configuration-> runtime-> assemblyBinding **并搜索具有name =“System.Web.Mvc”的assemblyIdentity并替换其值。

There should be same in all assemblyBinding version in main web.config and each Area views web.config file. 主web.config中的所有assemblyBinding版本应该相同,并且每个Area查看web.config文件。 I have got the same error please find the difference between main web.config and Area view. 我有同样的错误,请找到主web.config和区域视图之间的区别。

You can find the System.Web.Mvc version is 4.0.0.0 in main web.config as 你可以在主web.config中找到System.Web.Mvc版本是4.0.0.0

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
            </dependentAssembly>
      <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="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

But one of my area web.config under views are 但是我的区域web.config之一是视图

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
     /pages>
  </system.web.webPages.razor>

Please check the System.Web.Mvc, Version you got the different version. 请检查System.Web.Mvc,版本,你得到了不同的版本。 So there should newer version in main config file and area views config file same. 所以主配置文件和区域视图配置文件应该更新版本相同。 so have change the main web.config file as : 所以将主web.config文件更改为:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
            </dependentAssembly>
      <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="5.2.3.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="WebGrease" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在非MVC ASP.NET Web窗体应用程序中使用System.Web.Mvc - Use System.Web.Mvc in non MVC ASP.NET Web Forms Application ASP.NET MVC Q1 2010的Telerik扩展:未编译:显示警告:找不到引用的组件&#39;System.Web.MVC&#39; - Telerik Extensions for ASP.NET MVC Q1 2010: Not compiling: Shows warning :The referenced component 'System.Web.MVC' could not be found 无法调试System.Web.MVC - Cannot debug System.Web.MVC 无法加载文件或程序集“System.Web.Mvc,版本=3.0.0.0,Elmah.MVC 问题” - Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Elmah.MVC issue 无法在“新”框中加载文件或程序集&#39;System.Web.Mvc,版本= 3.0.0.0 - Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0 on NEW box 无法加载文件或程序集&#39;System.Web.Mvc,版本= 5.2.3,区域性=中性,公钥 - Could not load file or assembly 'System.Web.Mvc, Version=5.2.3, Culture=neutral, PublicKey 出现错误-无法加载文件或程序集&#39;System.Web.Mvc,版本= 4.0.0.0 - getting error-could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0 部署到Azure问题:无法加载文件或程序集&#39;System.Web.Mvc,版本= 5.2.3.0…清单不匹配问题 - Deploy to Azure issue: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0…manifest not match issue 无法在MVC 5中加载文件或程序集&#39;System.Web.Mvc&#39; - Could not load file or assembly 'System.Web.Mvc' in mvc 5 Asp.Net MVC 5和Hottowel 2.01 / Breeze - 无法加载文件或程序集&#39;System.Web.Http,Version = 4.0.0.0,...或其依赖项之一 - Asp.Net MVC 5 and Hottowel 2.01/Breeze - Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, … or one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM