Remote Debugging with Windows Azure

I’ve recently found myself (as well as other developers at The Nerdery) relying on the Websites feature of Windows Azure for hosting everything from our scratch pad web applications and API’s on up to our production apps. Recently, while doing a deployment to one of our production websites on Azure, I found myself facing an Object Reference error which couldn’t be reproduced in any other non-production environment. Luckily, with the release of the Azure SDK 2.2, Microsoft enabled remote debugging of your website instances.

Steps:

1. First things first you obviously need to have a website hosted on Azure to connect to. Using the existing portal you should see something like the following when logged into Azure under the Web Sites section:

Web Sites view

If you’re using the new Azure portal you’ll be able to view your websites by going to Browse -> Websites.

2. (note: I only performed these steps in Visual Studio 2013). In VS2013, within the Server Explorer window (and assuming that you’ve installed the Azure SDK 2.2) you should see a window tab for connecting to your Azure applications:

Server Explorer

If you haven’t already done so a screen will pop up prompting you for your Azure account credentials. Once you’ve entered them you should see your website(s) listed beneath the Web Sites section of the tree. Make sure that you have the code for the application you wish to debug loaded before continuing.

3. Right click on the website you’re interested in debugging and click on View Settings. This will open up a window that allows you to configure a number of your website’s properties remotely. The setting we’re interested in is the Remote Debugging property. Set it to On:

Website settings

4. You should now be able to again right click on the website entry you want to debug beneath the Websites section and click on the Attach Debugger button. This will launch your application in your default browser:

Attach Debugger

If everything went according to plan you should now be able to debug your application remotely! This was invaluable to me when it came to troubleshooting some pesky bugs in our application code. If you click the Attach Debugger button and end up with the following error:

Error

You’ll need to go into your Visual Studio options under Tools -> Options, click on the Debugging node, scroll all the way down to the bottom of the scroll pane on the right, and make sure that Use Managed Compatability Mode is unchecked:

Managed Compatibility Mode

Let me know how it works out for you!