Remotely Debugging Web Jobs on Windows Azure Websites

Yesterday I posted up some thoughts about how to streamline deployment of .NET-based Web Jobs along with your web-application. Continuing on with Web Jobs I thought it might be interesting to figure out how to debug them once they are deployed. With Windows Azure it is now possible to remotely debug a web application via Visual Studio when it is running in Windows Azure Websites.

Using the same mechanism it is also possible to attach to a running Web Job process which can help you dig into problems in Web Job execution during development (I wouldn’t recommend attaching a debugger on a production site). Unfortunately the process is a little kludgey right now so I’m not sure how effective this would be as a “normal-case” debugging scenario, but it’ll work in a pinch.

Before your start, to help you with the timing issue you might like to insert a Thread.Sleep(…) into your job just to give you enough time to attach to the process. Once you’ve got that updated Web Job code deployed start the debugger by attaching to the Windows Azure Website via the Attach Debugger menu option in Server Explorer.

AttachDebugger

Visual Studio will then spin away loading symbols etc. Once that is done go into the Windows Azure management console and start the web-job. At this point you need to work fast (depending on the value of the Thread.Sleep(…) that you put in.

Go into the “Debug | Attach to Process” menu item and select the web-site you are debugging from the Qualifier drop down (this is the remote debugging session that is currently supporting your web-app debugging). What you should see is your web-job executable in the list of available processes.

AttachToWorker

 

Once the debugger is attached any breakpoints that you have set within the web-job code will be hit and you can step through line by line.

BreakpointHit

 

Bingo! So now you know how to debug Web Jobs remotely via Visual Studio. I’d really like to see this process streamlined a bit so that when you attach a debugger to the web-site it automagically will hit breakpoints in the web-jobs that are part of the overall deployment.

 

4 thoughts on “Remotely Debugging Web Jobs on Windows Azure Websites

  1. Matt

    Hi Mitch thanks for the reply. I guess where I am confused is why can’t the breakpoint(s) be set and *then* start the process for debugging, as could be done in a local scenario?

  2. matthewgkrieger

    Hi Mitch thanks for the reply. Where I am confused is why can’t the breakpoint(s) be set and *then* start the process for debugging, just like in a local scenario?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s