Jonas Stensved
Jonas Stensved

Reputation: 15286

Netcoreapp2.0 won't start in Azure App Service with Error 500 and no logs

All of a sudden my Azure App Service can't start a aspnetcore2.0 and there is no logs. Just error 500 and no logs in Application Insights or Streaming Servicecs in Kudu.

App works perfectly on localhost, but standalone and with IIS Express and was working fine before in Azure yesterday.

How can I troubleshoot this?

Upvotes: 1

Views: 714

Answers (1)

Jonas Stensved
Jonas Stensved

Reputation: 15286

TL;DR; Azure is probably having issues with binding redirects due to other runtimes and .NET versions. Add this to your csproj in the calling code (usually your web project).

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

Troubleshooting steps:

  1. Enable startup logging

    public static IWebHost BuildWebHost(string[] args) => WebHost
        .CreateDefaultBuilder(args)
        .CaptureStartupErrors(true)
        [...]
    
  2. Open Kudu tools and watch the streaming log service

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

where you might find an error like:

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

[..]

Look for places where your code might load an assembly, I found out that:

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

Which is where I add my Azure Search code in my app.

  1. Either add missing assemblies, or as in my case where Azure Search SDK was referencing old assembly, enable AutoGenerateBindingRedirects as described in top of this post.

Upvotes: 3

Related Questions