ASP.NET Core HTTP Error 502.5 in Azure WebApp
Your .net core app has been running happily in Azure for a long time, and then suddenly, after a deploy you get a 502.5 HTTP Error thrown in your face. It “works on my machine”, it builds and passes all tests on your buildserver. Where do you start?
After skimming trough some threads in GitHub I realized that this would take some time. So I got a big cup off coffee, turned of Slack, Skype, mobile and locked the door.
I hope you can solve your 502.5 in Azure with the help of this short post.
Use the Console in the WebApp-blade
There is a lot of options for logging and functions in Azure, but non of them helped me much. Just generic “application could not be loaded”-non-helpful errors.
What I ended up doing was going to the “Console” in the WebApp-blade, under Development Tools, in the Azure Portal. And from that command prompt I ran what IIS is doing behind the scenes. When I did that, I immediately saw the error. My issue was that I had upgraded Visual Studio 2017 to version 15.2, and that installed a newer version of dotnet Core SDK and runtime that was not yet available in Azure.
When I specified the exact version of the runtime framework version I would like to use in the csproj-file, and redeployed, my site was back up in Azure, and it still worked on my machine. Whow.
Added the RuntimeFrameworkVersion tag in the .csproj file:
<PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion> <!-- Please use 1.1.1 --> </PropertyGroup>
To be honest, I do not fully understand all the details of all the moving parts like SDKs, runtimes, netstandards, tools and nugets with all the different version-numbers flying around. What is what, and what depends on what?! I can at this moment in time, while Azure is not updated with the newest runtime, consistently recreate this error by creating a new empty project with the dotnet cli and publish it straight to Azure with no changes. Not everyone can, or will, spend time on debugging errors like the 502.5, and I fear that some people will turn their back on .net Core for the wrong reasons. Hopefully it will get better as dotnet core matures. Still, having a template that does not work out-of-the-box in Azure is not good.
Find other errors
If you for example have an invalid connectionstring or any other invalid values in the appsettings.json these errors will also be easy to spot using the same strategy. For example an error in the startup would clearly readable in the console. You do of course have the app.UseDeveloperExceptionPage()-middleware, but sometimes the error can happen before that middleware even has a chance to run.
Links and resources
Here are some of the documentation, blogs and threads I ended up digging through search of a fix for my 502.5 error. Maybe some of these will solve your problem.
A GitHub issue with the exact same problem that took me hours to figure out
The specified framework ‘Microsoft.NETCore.App’, version ‘1.1.2’ was not found.
And a Stack-question with the same problem and solution
Azure Web Apps and .NET Core 1.1.2
Do you have any tips or tricks that could help people debug 502.5 errors in Azure, please leave a comment below.