简体   繁体   English

无法加载文件或程序集 System.Web.Mvc 或其依赖项之一

[英]Could not load file or assembly System.Web.Mvc or one of its dependencies

currently working on asp.net mvc5 (old mvc3 project).目前正在研究 asp.net mvc5(旧的 mvc3 项目)。 It builds just fine, but when I start the project but when I run the project I am facing the following error.它构建得很好,但是当我启动项目但运行项目时,我面临以下错误。

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)

Not sure how I can can fix this, any ideas?不知道如何解决这个问题,有什么想法吗?

This is the Assembly Load Trace:这是装配负载跟踪:

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

Web config: Web 配置:

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

If you carefully read the fusion log you posted, it gives you the information you need.如果您仔细阅读您发布的融合日志,它会为您提供所需的信息。 I'll strip it down to the important lines.我将把它剥离到重要的行。

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

The app is looking for System.Web.Mvc.dll.该应用正在寻找 System.Web.Mvc.dll。 It's resolved it to the one under your web app's bin folder: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin\System.Web.Mvc.DLL It's resolved it to the one under your web app's bin folder: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin\System.Web.Mvc.DLL

Next, it checks to see if there is any assembly binding redirect for that DLL in your web.config, and finds one:接下来,它会检查您的 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

If you look in your web.config, there will be something like this:如果你查看你的 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>

It then checks that the System.Web.Mvc.dll it's found in your app's bin directory is the same version:然后它会检查在您的应用程序的 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.

It complains that the Major Version mismatches.它抱怨主要版本不匹配。 This is the first number in the 4-number version.这是 4 号码版本中的第一个号码。 If you go back in the log, that's because the System.Web.Mvc.dll in your bin folder is actually version 4 .0.0.1, not the desired 5 .2.3.0:如果你在日志中返回 go,那是因为你的 bin 文件夹中的 System.Web.Mvc.dll 1 :实际上不是版本4 .0.3。

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

You need to check your solution to make sure all projects that reference System.Web.Mvc are looking for the same, latest version.您需要检查您的解决方案以确保所有引用 System.Web.Mvc 的项目都在寻找相同的最新版本。 If you look at the Warnings in the Error List, you'll likely find warnings about version mismatches for this assembly.如果您查看错误列表中的警告,您可能会发现有关此程序集的版本不匹配的警告。

Updating References更新参考

One solution is to right click on the Solution in Visual Studio, choose "Manage NuGet Packages for Solution..." and try to update the projects to use the same version of System.Web.Mvc.一种解决方案是在 Visual Studio 中右键单击解决方案,选择“Manage NuGet Packages for Solution...”并尝试更新项目以使用相同版本的 System.Web.Mvc。

It will also help if you clear out your bin folders beforehand.如果您事先清除 bin 文件夹,也会有所帮助。

You can also use the Package Manager Console instead to update the package across your solution:您还可以使用 Package 管理器控制台来更新您的解决方案中的 package:

Update-Package Microsoft.AspNet.Mvc -version 5.2.3.0

I'm not really sure if this will help.我不确定这是否会有所帮助。 But I also had this message:但我也收到了这样的信息:

Could not load file or assembly 'System.Web.Mvc (1)' or one of its dependencies...无法加载文件或程序集“System.Web.Mvc (1)”或其依赖项之一...


I don't really know why but when I check out the bin folder of the web application, some of the DLL files have duplicates like " System.Web.Mvc(1).dll " and so on. I don't really know why but when I check out the bin folder of the web application, some of the DLL files have duplicates like " System.Web.Mvc(1).dll " and so on.

What I did was, I deleted all the duplicate files (file names with '(1)' or '(2)'... on it) , then rebuild the web app then it worked again.我所做的是,我删除了所有重复的文件(文件名带有 '(1)' 或 '(2)'...) ,然后重建 web 应用程序,然后它再次工作。

Could you post your web.config file here?.你能在这里发布你的 web.config 文件吗? It seems that you opened a mvc3 project in a newer environment and the migrating function of your IDE (ie Visual Studio) doesn't work well.似乎您在较新的环境中打开了一个 mvc3 项目,并且您的 IDE(即 Visual Studio)的迁移 function 不能正常工作。 The versions of System.Web.Mvc.DLL are mismatched (in config file and the one in bin/ directory). System.Web.Mvc.DLL 的版本不匹配(在配置文件和 bin/ 目录中)。 There are two ways to solve this: 1. Modify the version of System.Web.Mvc package/assembly in the config file.有两种解决方法: 1. 修改配置文件中 System.Web.Mvc package/assembly 的版本。 2. Copy System.Web.Mvc.dll from your old project to the new project (bin/ folder). 2. 将 System.Web.Mvc.dll 从旧项目复制到新项目(bin/文件夹)。

I had faced the similar issue for other.dll files before.我之前遇到过 other.dll 文件的类似问题。 At that time, I chose to delete all.dll files and use NuGet Package Manager to download them again.当时我选择删除所有.dll文件,使用NuGet Package Manager重新下载。

You need to just simply update your MVC to desired version.您只需将 MVC 更新到所需的版本即可。 In your Solution Explorer right click on References -> select Manage Nuget Packages Manage Nuget then select Browse tab-> search for MVC-> select desired version select version -> install. In your Solution Explorer right click on References -> select Manage Nuget Packages Manage Nuget then select Browse tab-> search for MVC-> select desired version select version -> install.

Once it get installed, try to run again.安装后,尝试再次运行。 It will resolve this error.它将解决此错误。

暂无
暂无

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

相关问题 找不到包含文档的“无法加载文件或程序集&#39;System.Web.Mvc&#39;或其依赖项之一” - Can't resolve “Could not load file or assembly 'System.Web.Mvc' or one of its dependencies” with documentation found 无法加载文件或程序集&#39;System.Web.Mvc(1)&#39;或其依赖项之一 - Could not load file or assembly 'System.Web.Mvc(1)' or one of its dependencies 无法加载文件或程序集“System.Web.Mvc,Version = 3.0.0.0”或其依赖项之一 - Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0' or one of its dependencies 无法加载文件或程序集“System.Web.Mvc”或其依赖项之一。 定位的程序集的清单定义与程序集不匹配 - 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 无法加载文件或程序集&#39;System.Web.Mvc&#39;或其依赖项之一。 2个项目。 一次只能工作一个 - Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. 2 projects. Only one will work at a time 无法在MVC 5中加载文件或程序集&#39;System.Web.Mvc&#39; - Could not load file or assembly 'System.Web.Mvc' in mvc 5 无法加载文件或程序集“ System.Web.MVC,版本4.0.0.0” - could not load file or assembly 'System.Web.MVC, version 4.0.0.0,' 无法加载文件或程序集System.Web.Mvc,版本= 5.2.3.0 - Could not load file or assembly System.Web.Mvc, Version=5.2.3.0 无法在单元测试中加载文件或程序集&#39;System.Web.Mvc - Could not load file or assembly 'System.Web.Mvc In Unit Test 无法加载文件或程序集System.Web.Mvc - Could not load file or assembly System.Web.Mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM