【问题标题】:Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Elmah.MVC issue无法加载文件或程序集 'System.Web.Mvc,版本 = 3.0.0.0,Elmah.MVC 问题
【发布时间】:2013-05-23 17:13:04
【问题描述】:

本地 - 我的 MVC 4、asp.net、c# 应用在 IIS 8 / Windows 8 上运行良好。

部署到 Windows Server 2008 时,我收到此错误:

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   Elmah.Mvc.Bootstrap.Initialize() +0

[InvalidOperationException: The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12881963
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12881672
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +240
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881108
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722297

如果我从项目属性/包/发布网络中的“要部署的项目”下拉列表中选择“仅运行此应用程序所需的文件”,就会发生这种情况。

如果我选择“此项目中的所有文件”,它就可以正常工作。

我猜 Elmah 依赖于旧版本的 MVC 或其他东西 - 我怎样才能在不上传所有文件的情况下解决这个问题?

解决此类问题的最佳方法是什么?

谢谢。

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-4 assemblies elmah.mvc


    【解决方案1】:

    我在使用 MVC4 和为 .Net 4.5 构建的 Ninject 时遇到了同样的问题

    要解决这个问题,我必须在我的 Web.config 文件中添加绑定重定向: (在文件末尾,就在</configuration> 标签之前)

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

    这会强制 Web 服务器使用 System.Web.Mvc 4.0.0.0 而不是旧版本。

    【讨论】:

    • 使用 asp.net mvc 5 版本将 2.0.0.0 替换为 3.0.0.0 - 将 4.0.0.0 替换为 5.0.0.0
    • 但是为什么会这样呢?如果没有 NInject,我也有同样的问题,而且对于我的一生,我无法弄清楚哪个程序集引用了 v3! FusionLogs 显示“某人”正在请求它,但调用程序集是未知的。我真的很想知道为什么。
    【解决方案2】:

    在错误页面中我有这个:

    LOG:在应用程序配置文件中检测到重定向:5.1.0.0 被重定向到 5.2.3.0。

    所以我不得不将 web.config 中的这一行更改为 5.1.0.0 版本,并且成功了!

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

    我认为这是由于我从 TFS 下载代码时的版本问题

    希望对你有帮助

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        有一些程序可以解决这个问题,如果web.config中的绑定重定向不能解决问题,您可以尝试以下步骤来解决它:

        1) 在 Visual Studio 解决方案资源管理器树中,右键单击 Web 项目下的引用,然后选择管理 NuGet 包。

        2) 转到浏览选项卡并选择nuget.org 作为包源。

        3) 搜索并安装以下软件包:NinjectNinject.Web.CommonNinject.MVC5

        最好在管理 NuGet 包的更新选项卡上更新包,尤其是 Microsoft ASP.NET MVC

        希望这会有所帮助...

        【讨论】:

          【解决方案5】:
          <dependentAssembly>
                      ***<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                      <bindingRedirect oldVersion="0.0.0.0-5.2.7.0"*** newVersion="5.2.7.0" />
                  </dependentAssembly>
          

          检查是否有正确的版本

          【讨论】:

            【解决方案6】:

            安装System.Web.Mvc 3.0.0.0版本

            1) 安装windows web platform installer
            2) 从开始菜单打开 Windows Web 平台安装程序
            3) 转到Products 标签
            4) 搜索 MVC
            5) 安装 MVC 3

            【讨论】:

            • OP 正在使用 MVC4 - 安装 MVC3 会适得其反。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-09-12
            • 1970-01-01
            • 2013-11-14
            • 2015-02-15
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多