【问题标题】:Could not load file or assembly System.Web.Mvc or one of its dependencies无法加载文件或程序集 System.Web.Mvc 或其依赖项之一
【发布时间】:2015-08-03 08:10:32
【问题描述】:

目前正在研究 asp.net mvc5(旧的 mvc3 项目)。 它构建得很好,但是当我启动项目但运行项目时,我面临以下错误。

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

不知道如何解决这个问题,有什么想法吗?

这是程序集负载跟踪:

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Web.Mvc | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/
LOG: Initial PrivatePath = C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config
LOG: Using host configuration file: C:\Users\joaki\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL.
LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config
LOG: Using host configuration file: C:\Users\joaki\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0.
LOG: Post-policy reference: System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

网络配置:

    <?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=301880
  -->
<configuration>
    <connectionStrings>
    <add name="SaleswebEntities" connectionString= ""/>
  </connectionStrings>

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5.1" >
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>

  <authentication mode="Forms">
    <forms loginUrl="~/Account/LogOn" timeout="2880" />
  </authentication>

  <membership>
    <providers>
      <clear />
      <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    </providers>
  </membership>

  <profile>
    <providers>
      <clear />
      <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>
  </profile>

  <roleManager enabled="false">
    <providers>
      <clear />
      <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
      <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
    </providers>
  </roleManager>

  <pages>
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="System.Web.Helpers" />
      <add namespace="System.Web.WebPages" />
    </namespaces>
  </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <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.WebPages" 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.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

【问题讨论】:

  • 看起来在引用的 DLL 和 web.config 中的程序集绑定之间存在 DLL 版本不匹配。检查这些
  • 严重性代码说明项目文件行警告无法解析此引用。找不到程序集“System.Web.Mvc,Version=2.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL”。检查以确保该程序集存在于磁盘上。如果您的代码需要此引用,您可能会遇到编译错误。 Salesweb.Common C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets 1819 好像我需要 System.web.mvc 2.0.0.0 而不是我拥有的最新版本。

标签: c# asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-5


【解决方案1】:

如果您仔细阅读您发布的融合日志,它会为您提供所需的信息。我会把它精简到重要的几行。

LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL.

应用正在寻找 System.Web.Mvc.dll。已将其解析为 Web 应用程序 bin 文件夹下的一个:C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin\System.Web.Mvc.DLL强>

接下来,它会检查您的 web.config 中是否有针对该 DLL 的任何程序集绑定重定向,并找到一个:

LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config
LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0.
LOG: Post-policy reference: System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

如果你查看你的 web.config,会有这样的东西:

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

然后它会检查它在您应用的 bin 目录中找到的 System.Web.Mvc.dll 是否为相同版本:

WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

它抱怨主版本不匹配。这是 4 号码版本中的第一个号码。如果您返回日志,那是因为您的 bin 文件夹中的 System.Web.Mvc.dll 实际上是版本 4.0.0.1,而不是所需的 5。 2.3.0:

LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0.

您需要检查您的解决方案,以确保所有引用 System.Web.Mvc 的项目都在寻找相同的最新版本。如果您查看错误列表中的警告,您可能会发现有关此程序集的版本不匹配的警告。

更新参考

一种解决方案是在 Visual Studio 中右键单击解决方案,选择“Manage NuGet Packages for Solution...”并尝试更新项目以使用相同版本的 System.Web.Mvc。

如果您事先清除 bin 文件夹也会有所帮助。

您也可以改用包管理器控制台来更新您的解决方案中的包:

Update-Package Microsoft.AspNet.Mvc -version 5.2.3.0

【讨论】:

  • 这确实解决了 MVC 问题.. 谢谢,但它确实给我留下了另一个问题,我现在将尝试解决。 System.MethodAccessException:尝试通过安全透明方法“System.Web.Mvc.PreApplicationStartCode.Start()”访问安全关键方法“System.Web.WebPages.Razor.PreApplicationStartCode.Start()”失败。感谢您的帮助
  • 这太复杂了...我最终启动了一个包含所有更新 NuGet 的新项目,然后我将所有旧项目代码转储到新项目中...漫长但有效
【解决方案2】:

我不确定这是否会有所帮助。 但我也收到了这样的信息:

无法加载文件或程序集“System.Web.Mvc (1)”或其其中之一 依赖...


我真的不知道为什么,但是当我检查 Web 应用程序的 bin 文件夹时,一些 DLL 文件有重复,如“System.Web.Mvc(1).dll”等等.

我所做的是,我删除了所有重复的文件(文件名带有'(1)' 或'(2)' ...),然后重建网络应用程序,然后它再次工作。

【讨论】:

    【解决方案3】:

    您能在此处发布您的 web.config 文件吗?您似乎在较新的环境中打开了一个 mvc3 项目,并且您的 IDE(即 Visual Studio)的迁移功能无法正常工作。 System.Web.Mvc.DLL 的版本不匹配(在配置文件和 bin/ 目录中的版本)。有两种方法可以解决这个问题: 1、修改config文件中System.Web.Mvc包/程序集的版本。 2. 将旧项目中的 System.Web.Mvc.dll 复制到新项目(bin/ 文件夹)中。

    我之前遇到过其他 .dll 文件的类似问题。当时我选择删除所有.dll文件,然后使用NuGet包管理器重新下载。

    【讨论】:

    • 发布我的网络配置,我会试试你写的。
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2012-01-14
    • 1970-01-01
    相关资源
    最近更新 更多