I have an ASP.NET Webforms Application on Azure but i always get the following Error on some sites: 502 - Web server received an invalid response while acting as a gatew
In my case, I got 502 errors because the site was restarted by the azure auto-heal system. It turns out I made tests with that auto-heal system a few days ago, but since in the end I disabled it, I didn't think it could cause my 502 errors.
This is where I discovered that the azure interface to change auto-heal settings (mywebsite.scm.azurewebsites.net/Support -> mitigate) only affects the production slot. But when you swap your deployment slots, the settings get swapped. There is apparently no way to directly change the staging slot settings, you have to swap, change settings, and swap again.
So, I ended up having my staging slot with auto-heal enabled, and my production slot with auto-heal disabled (and of course at that time I thought it was disabled on both slots). Then I was "randomly" hitting 502 errors either on staging or production depending on how many times I swapped them. What's weird is that though the application seems to restart (or at least fails to respond to a few requests), I don't get the corresponding events in my log file, like if it wasn't running Application_Start after an app pool recycle triggered by the auto-heal system.
Took me a whole day to find out what was happening, I hope this answer can help someone in the same situation.
I got the error for a while after fiddling with connection strings, went away and came back in an hour, and the issue had disappeared and the site worked normally again. A highly technical answer for you.
That points to an application issue. The reason you are etting 502 is because the worker process is crashing and the front end is left with a request with no response and returning a 502 to say exactly that. Look for eventlog.xml
under the LogFiles folder for your website. Alternatively you can try remote debugging from VS to your website.
System.Windows.Forms.dll
contains a lot of UI code that will most probably not work Azure websites sandbox. The reason it's loaded is probably because you are using something from the assembly or using something that uses something from that assembly. It doesn't have to be listed in Visual Studio to be loaded since it's a part of the standard .NET Framework.
I would suggest looking into remote debugging and figuring out at what point this is getting loaded and why.