【问题标题】:Asp.net MVC 5.2.2 on AzureAzure 上的 Asp.net MVC 5.2.2
【发布时间】:2014-10-21 15:28:24
【问题描述】:

在将 mvc nuget 包从版本 5.1.0 升级到 5.2.2 后,我们在 Azure 上的机器 (webrole) 拒绝启动 Web 角色。它处于回收状态。我在事件日志中发现错误:

    The description for Event ID 1007 from source Windows Azure Runtime 2.4.0.0 cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

820
WaIISHost
Role entrypoint could not be created: System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.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)
File name: 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

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

 ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum) 
the message resource is present but the message is not found in the string/message table

我试图通过互联网搜索,但没有有用的答案。 除了降级,我无法解决它。幸运的是 5.1.1 版本的软件包正在运行。

更新 1: 经过反复试验,我发现 asp.net mvc 包在 5.1.3 版之前都可以 似乎不支持 5.2.0 以上的软件包。

更新 2: 我们决定拆分我们的 web 和 web.api,所以我不再有这个问题了。我最好的猜测是,确实存在 nuget,它引用了旧的 asp.net mvc 包。

【问题讨论】:

  • 您是否将新的 MVC dll 复制到您的应用程序 bin 文件夹中?
  • @TomTom 我假设,这是由 nuget 包升级自动完成的。我在调查期间对此进行了检查,并将 Copy Local 设置为 True。

标签: c# asp.net-mvc azure asp.net-mvc-5.2


【解决方案1】:

我遇到了类似的问题。我们继承了一个项目并将 ASPNET MVC 版本更新为 5.2.2.0。我们无法部署到 Azure。我们能找到的唯一错误是您在此处提到的错误。

我们更正了每个 web.config 文件,因此旧版本被重定向到新版本,但我们仍然遇到同样的问题。

然后我们编写了一个小测试方法来迭代每个程序集,我们看到一个 NuGet 包仍在使用 Asp.net MVC 4.0。这个包是一个旧版本,有一段时间没有更新了。我下载了源代码,更新了 Mvc Nuget 并手动插入了 dll。

我们再次部署,一切顺利。

这里是测试方法。

 private void TestAssemblies()
    {
        var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
        foreach (Assembly item in allAssemblies)
        {
            PrintAssembly(item);
        }
    }
    private void PrintAssembly(Assembly assembly)
    {
        foreach (var item in assembly.GetReferencedAssemblies())
        {
            if (item.FullName.Contains("System.Web.Mvc"))
            {

                Debug.WriteLine(item);
                Debug.WriteLine("Parent: " + assembly.FullName);
                Debug.WriteLine("------------------------------------------------------------");
            }
        }
    }

【讨论】:

  • 非常非常有用 - 原来 nuget 下载的包引用了 4.0.0 版本,我相信这会导致 5.2.2 失败。如果不是上面的测试方法,永远不会发现这一点。
【解决方案2】:

MVC 5.2.2 在 Azure 中运行良好。您的角色回收很可能表明您没有正确部署应用程序,或者您对绑定重定向可能无法处理的旧版 MVC 存在隐藏依赖。

我强烈建议您阅读 Kevin Williamson 的 great series on trouble shooting Azure deployments 中的所有条目。

有很多事情可能出错,所以与其尝试创建一个通用的万能列表,不如查看博客文章,然后发表评论,如果你是无法弄清楚具体发生了什么。

鉴于您发布的错误,假设您有@Yishai Galatzer 提到的正确绑定重定向,您的部署中可能有一个对 MVC 5.1.0.0 具有隐藏依赖关系的 DLL。我建议使用像 Jetbrains DotPeek 这样的程序来检查包中的所有 DLL 并查看它们的引用。我怀疑你会找到一个本身依赖于 5.1.0.0 的。

【讨论】:

  • '你的角色回收很可能表明你没有正确部署你的应用程序'--不,这表明 WebRoles 和 WorkerRoles 由于这个 dll 问题通常是一个巨大的痛苦导致部署严重失败的冲突,并且没有提供有关原因的有用信息。长久以来的情况如此,简直令人无法接受。像这样 1 周前又经历了 24 小时的痛苦之后,我终于迁移到了 azure 上的网站,并且安装了相同的代码没有问题。
  • @Nicholas :) 这表明 Azure 是一个巨大的痛苦。它不应该这么复杂。我在同样的问题上浪费了一整天。
  • @DavidPeden 实际上,我不推荐 Jetbrains DotPeek 执行此任务,因为它不会显示所有引用(似乎它隐藏了它无法找到的引用程序集)。我花了很多时间,直到我重新检查另一个反汇编程序(Telerik 的 Just Decompile)中的依赖关系以找出 Microsoft.Azure.WebJobs.Host, Version=1.0.1.0 引用 Microsoft.WindowsAzure.Storage, Version=4.0.1.0
【解决方案3】:
I have also face similar problem with mvc5.2.2 azure deployment..

最终的解决方案是我们需要添加这个 web.config

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

【讨论】:

    【解决方案4】:

    从外观上看,您的 web.config 中似乎缺少到 MVC 5.2.2 的绑定重定向。这应该只是工作。

    我们正在努力验证这种情况。但是,让我们知道这是否适合您。请在您的 web.config 中查看以下部分,并确保它与以下 xml 匹配:

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

    【讨论】:

    • 我在 web.config &lt;dependentAssembly&gt; &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt; &lt;bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /&gt; &lt;/dependentAssembly&gt; 中有此部分,但我的 webrole 仍在回收中。如果有帮助,它的位置是西欧。
    • 几天前我遇到了完全相同的问题。请参考这篇文章。您需要将 部分添加到 WaIISHost.exe.config,这通常是您 VM 上的 @'E:\base\x64'。
    【解决方案5】:

    几天前我遇到了完全相同的问题。请参考this 帖子。 您需要将 &lt;dependentAssembly&gt; 部分添加到 WaIISHost.exe.config,这通常是您 VM 上的 @'E:\base\x64'

    【讨论】:

      【解决方案6】:

      很多时候我发现问题出在 ~\Views\Web.config 文件中。它保留对旧 MVC 版本的引用。只需手动更新即可。

      如果这不起作用,请在 Sublime Text 或 VS 之外的其他工具中对您的解决方案进行全文搜索,然后搜索导致您出现问题的版本字符串。

      【讨论】:

        【解决方案7】:

        我遇到了同样的问题,它在我的开发机器上运行良好,但是在部署时我遇到了组装错误。为了解决这个问题,我不得不将“oldVersion”从版本 0.0.0.0 更改为版本 1.0.0.0

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

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

        【讨论】:

          猜你喜欢
          • 2014-12-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-24
          • 1970-01-01
          • 2010-11-02
          • 2016-03-21
          • 1970-01-01
          相关资源
          最近更新 更多