I was refactoring my .NET core 2.2 based Web Api to make use of reusable a HttpClient. It all looked fine. But in the end my Api only threw 502 Bad Gateway errors.
Now, to find out what causes this unexpected behaviour, I went back a few steps in my refactoring work. I found that only adding the Microsoft.Extensions.Http package to my project is what makes my application start to throw those 502's.
So no code changes, just adding the package via NuGet. I added Microsoft.Extensions.Http version 5.0.0.0.
Does anyone have a clue why this is?
I’m running my app in debug mode in Visual Studio 2022 / IISExpress
CodePudding user response:
.NET doesn't typically return a 502 status code, so this error is most likely with your hosting setup.
502 - Bad Gateway is typically returned by a load balancer / reverse proxy when either there are no nodes in the pool (i.e. the application didn't start up properly), or the node crashes while servicing the request.
In either case, you'll need to check the logs on the host to see which case is correct. My guess is if this started happening after you installed the package, the runtime on the server is incompatible with it or the package is simply misconfigured.
