发布的MVC3应用程序导致:“无法加载文件或程序集'System.Web.Mvc'”

时间:2013-12-31 07:37:26

标签: asp.net-mvc-3 visual-studio-2012 azure-web-sites

我正在尝试将一个新的MVC3项目部署到Azure网站。

步骤:

  1. 使用Razor View Engine在VS 2012中创建新的MVC3 Internet应用程序。添加到web.config文件。
  2. F5在本地构建和调试,验证该站点是否在本地调试中加载。
  3. 创建一个新的azure网站并下载该网站的发布设置文件。
  4. 使用步骤3中下载的发布设置发布网站。
  5. EXPECT>>网站在发布时按预期加载。

    ACTUAL>> “无法加载文件或程序集'System.Web.Mvc,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。” (下面的完整堆栈跟踪)

    我知道这个示例项目过去常常为我发布而没有错误,但是我没有尝试过一年左右。

    我在Stackoverflow上看到过类似的错误,但答案要么不相关,要么不完整:

    我很长时间以来一直在追逐我的尾巴。有没有人有任何建议?

        Server Error in '/' Application.
    --------------------------------------------------------------------------------
    
    
    Could not load file or assembly 'System.Web.Mvc, Version=4.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) 
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
     Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.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)
    
    Source Error: 
    
    
     An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
    
    
    
    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
    
    
    
    Stack Trace: 
    
    
    
    [FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=4.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)]
       Microsoft.Web.Mvc.ViewEngineFix.PreAppStart() +0
    
    [InvalidOperationException: The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.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) +550
       System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +140
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
    
    [HttpException (0x80004005): The pre-application start initialization method PreAppStart on type Microsoft.Web.Mvc.ViewEngineFix threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=4.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) +9877836
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext 
    

1 个答案:

答案 0 :(得分:3)

在您的问题中,您声明您的目标是MVC3,但看起来Azure机器找不到该程序集的正确版本。它正在寻找MVC二进制文件。这让我相信您尝试发布的服务器上没有安装MVC3。

您可以选择几种方式:

  1. Upgrade your project to MVC4 and publish the upgraded version
  2. web.config to redirect MVC3 to MVC4 at runtime
  3. 中应用一组BindingRedirects

    这是我认为你需要的一组绑定重定向,可能还有其他重定向,但你会得到一个类似的错误:

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