Debug .Net Core in Azure App Service from Visual Studio
Tags: netcore, azureappservice, debugging, visualstudio
Published: 2019-10-10 21:56:39

OK, I must confess, I said: It works on my machine.
When I uploaded my code to DEV environment.. ¡Surprise! It crashes.
After doing some test in both, my local and dev environments, checking App Insights, Google and find out nothing, I decided to attach Visual Studio debugger to the Web App (only after telling my team about it, and only because it was DEV environment).
Thus, make sure that the App Service on Azure has remote debugging enabled.
![Debugging — Remote Debugging: On. Visual Studio Version: 2019](https://thepracticaldev.s3.amazonaws.com/i/hzyd7ssks0njeienwfdv.png)
*MyAppService -> Configuration -> General Settings -> Debugging*


Let’s attach the debugger from Visual Studio:
![Cloud Explorer -> MySubscription -> AppServices -> rightclic en MyAppService -> Attach debugger](https://thepracticaldev.s3.amazonaws.com/i/dh5o1zcxc5gw4a7n8n7k.png)
*Cloud Explorer -> MySubscription -> AppServices -> rightclic en MyAppService -> Attach debugger*


Suddenly, a wild Pop Up appears on Visual Studio with something I’ve never ever seen:
![Unable to attach to application ‘dotnet.exe’ (PID: 9504) using ‘mywebapp’.](https://thepracticaldev.s3.amazonaws.com/i/v58ift7t0fklrtkitydn.PNG)
*Unable to attach to application ‘dotnet.exe’ (PID: 9504) using ‘mywebapp’. The 64-bit version of the Visual Studio Remote Debugger (MSVSMON.EXE) cannot be used to debug 32-bit processes or 32-bit dumps. Please use the 32-bit version instead.*


It seems that I’m trying to attach a 64 bit debugger to a 32 bit process. However, my Web App is configured to run on 64 bit:
![Platform Settings — Platform: 64 Bit](https://thepracticaldev.s3.amazonaws.com/i/imwpiywtnwtv4g36ekbi.png)
*MyAppService -> Configuration -> General Settings -> Platform Settings*


How can the process run on 32 bit? Let’s check KUDU. We now can see that the .NET Core process that runs our application is on 32 bit:
![Kudu -> Process Explorer -> rightclick en dotnet.exe(PID:9504)](https://thepracticaldev.s3.amazonaws.com/i/gi27u0gcalpsy79iveb6.png)
*Kudu -> Process Explorer -> rightclick en dotnet.exe(PID:9504)*


It turns out that [.NET CORE 2.2 SDK available by default at the Azure App Services is for 32bits](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/?view=aspnetcore-2.2&tabs=visual-studio#application-configuration)
Thus, it does not take any effect configuring the Web App in 64 bit on Azure Portal. The IIS Worker Process, even running on 64 bit, will spawn .NET Core on 32 bit (due to .NET Core is only available by default on 32 bit). So the Visual Studio Debugger we should attach is the one on 32 bit as well.
If we configure the WebApp to run on 32 bit, Visual Studio will try to attach the 32 debugger this time:
![Platform Settings — Platform: 32 Bit](https://thepracticaldev.s3.amazonaws.com/i/cbaxbgcgqxuvzwmwfpd3.png)
*Azure Portal → MyWebApp -> Configuration → General Settings → Platform Settings — Platform: 32 Bit*


Nevertheless, if you want to run your application in 64 bit, you can configure the hosting model as InProcess. More info [here](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2#in-process-hosting-model).