【问题标题】:Netcoreapp2.0 won't start in Azure App Service with Error 500 and no logsNetcoreapp2.0 无法在 Azure 应用服务中启动,错误 500 且没有日志
【发布时间】:2018-05-23 13:08:00
【问题描述】:

突然间我的 Azure App Service 无法启动 aspnetcore2.0 并且没有日志。只是错误 500,并且 Kudu 中的 Application Insights 或 Streaming Servicecs 中没有日志。

应用程序在 localhost 上完美运行,但独立且与 IIS Express 一起使用,并且昨天在 Azure 中运行良好。

我该如何解决这个问题?

【问题讨论】:

    标签: azure azure-web-app-service asp.net-core-2.0


    【解决方案1】:

    TL;DR;由于其他运行时和 .NET 版本,Azure 可能存在绑定重定向问题。在调用代码(通常是您的 Web 项目)中将此添加到您的 csproj。

    <PropertyGroup>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    </PropertyGroup>
    

    故障排除步骤:

    1. 启用启动日志记录

      public static IWebHost BuildWebHost(string[] args) => WebHost
          .CreateDefaultBuilder(args)
          .CaptureStartupErrors(true)
          [...]
      
    2. 打开 Kudu 工具,观看流式日志服务

      https://.scm.azurewebsites.net/api/logstream

    您可能会发现如下错误:

    2017-12-09 11:53:33.304 +00:00 [Error] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HL9UVDQACN2F", Request id "0HL9UVDQACN2F:00000002": An unhandled exception was thrown by the application.
    System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    File name: 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
       at Microsoft.Rest.ServiceClient`1.CreateRootHandler()
    

    [..]

    寻找你的代码可能加载程序集的地方,我发现:

    File name: 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
       at Microsoft.Rest.ServiceClient`1.CreateRootHandler()
       at MyApp.MiddleLayer.Services.AzureSearch.DependencyInjection.<>c.<AddAzureSearch>b__0_1(IServiceProvider x) in C:\<Path>.Services.AzureSearch\DependencyInjection.cs:line 27
    

    我在应用中添加 Azure 搜索代码的位置。

    1. 要么添加缺少的程序集,要么就像我在 Azure 搜索 SDK 引用旧程序集的情况下一样,启用 AutoGenerateBindingRedirects,如本文顶部所述。

    【讨论】:

    • 所以在您没有进行任何新部署的情况下它突然中断了?您是在 .NET Core 上还是在 Full Framework 上使用 ASP.NET Core?您可以直接或indirectly 分享您的网络应用名称吗?另外,您能否检查一下它是否已更新到 2016 年,以防万一?
    • 不,它在部署后坏了,但之前工作过。使用 .NET Core 2.0。 Azure 搜索 SDK 打破了它。
    • Azure上的构建过程应该和VS中的一样,我猜System.Net.Http.WebRequest是在你本地测试的时候从nuget cache加载的,你可以试试1.发布到local folder看看是否出现了缺少的程序集?还是2.清除缓存再运行?
    • 我清除了缓存,所以不可能这样。好像我的本地机器上的版本和 Azure 上的部署版本不匹配。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 2016-08-28
    • 2013-03-27
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多