Debugging a Cloud Service in Visual Studio
You can save time and money by using the Windows Azure compute emulator to debug your cloud service on a local machine. By debugging a service locally before you deploy it, you can improve reliability and performance without paying for compute time. However, some errors might occur only when you run a cloud service in Windows Azure itself. You can debug these errors if you enable remote debugging when you publish your service and then attach the debugger to a role instance.
|The remote debugging feature is offered as a Community Technology Preview (CTP) and is still under development.|
The emulator simulates the Windows Azure Compute service and runs in your local environment so that you can test and debug your cloud service before you deploy it. The emulator handles the lifecycle of your role instances and provides access to simulated resources, such as local storage. When you debug or run your service from Visual Studio, it automatically starts the emulator as a background application and then deploys your service to the emulator. You can use the emulator to view your service when it runs in the local environment.
You can run the full version or the express version of the emulator. See Debugging a Cloud Service with Emulator Express.
To debug a cloud service from a remote machine, you must enable that functionality explicitly when you deploy your cloud service so that required services (msvsmon.exe, for example) are installed on the virtual machines that run your role instances. If you enable remote debugging for a cloud service, it doesn't exhibit degraded performance or incur additional charges. You shouldn't use remote debugging on a production service, because clients who use the service might be adversely affected.
|When you publish a cloud service from Visual Studio, you can enable IntelliTrace for any roles in that service that target the .NET Framework 4 or the .NET Framework 4.5. By using IntelliTrace, you can examine events that occurred in a role instance in the past and reproduce the context from that time. See Debugging a Published Cloud Service with IntelliTrace and Visual Studio and Debugging With IntelliTrace.|
To debug your cloud service on your local computer
On the menu bar, choose Debug, Debug.
Display the user interface for the compute emulator by opening the shortcut menu for the Windows Azure icon in the notification area and then choosing Show Compute Emulator UI.
The left pane of the UI shows the services that are currently deployed to the compute emulator and the role instances that each service is running. You can choose the service or roles to display lifecycle, logging, and diagnostic information in the right pane. If you put the focus in the top margin of an included window, it expands to fill the right pane.
Step through the application by choosing commands on the Debug menu and setting breakpoints in your code.
As you step through the application in the debugger, the panes are updated with the current status of the application. When you stop debugging, the application deployment is deleted.
If your application includes a web role and you've set the Startup action property to start the web browser, Visual Studio starts your web application in the browser.
If you change the number of instances of a role in the service configuration, you must stop your cloud service and then restart debugging so that you can debug these new instances of the role.
|When you stop running or debugging your service, the local compute emulator and storage emulator aren't stopped. You must stop them explicitly from the notification area.|
Debugging a cloud service in Windows Azure
You can attach the debugger to a running cloud service in Windows Azure only if you enabled remote debugging when you published the service. If you didn't, you must republish the service with remote debugging enabled.
To enable remote debugging for a cloud service
Open the shortcut menu for the Windows Azure project, and then choose Publish.
Choose the Staging environment and the Debug configuration.
You may adversely affect users if you enable remote debugging on the Production environment. You can choose the Release configuration, but the Debug configuration makes debugging easier.
Follow the usual steps, but select the last check box on the Advanced Settings tab.
To attach the debugger to a cloud service in Windows Azure
In Server Explorer, expand the node for your cloud service.
Open the shortcut menu for the role or role instance to which you want to attach, and then choose Attach Debugger.
If you choose a role, the Visual Studio debugger attaches to each instance of that role. The debugger will break on a breakpoint for the first role instance that runs that line of code and meets any conditions of that breakpoint. If you choose an instance, the debugger attaches to only that instance and breaks on a breakpoint only when that specific instance runs that line of code and meets the breakpoint's conditions.
After the debugger attaches to an instance, debug as usual.
The debugger automatically attaches to the appropriate host process for your role. Depending on what the role is, the debugger attaches to w3wp.exe, WaWorkerHost.exe, or WaIISHost.exe. To verify the process to which the debugger is attached, expand the instance node in Server Explorer.
To identify the processes to which the debugger is attached, open the Processes dialog box by, on the menu bar, choosing Debug, Windows, Processes. (Keyboard: Ctrl+Alt+Z)
To detach a specific process, open its shortcut menu, and then choose Detach Process. Or, locate the instance node in Server Explorer, find the process, open its shortcut menu, and then choose Detach Process.
|Avoid long stops at breakpoints when remote debugging. Windows Azure treats a process that's stopped for longer than a few minutes as unresponsive and stops sending traffic to that instance. If you stop for too much time, msvsmon.exe shuts down and terminates your process.|
To detach the debugger from all processes in your instance or role, open the shortcut menu for the role or instance that you're debugging, and then choose Detach Debugger.
Limitations of remote debugging in Windows Azure
For Windows Azure SDK 2.2, remote debugging is offered as a technology preview, and you should understand the following limitations.
With remote debugging enabled, you can't publish a cloud service in which any role has more than 25 instances.
Native debugging isn't supported.
The debugger uses ports 30400 to 30424 and 31400 to 31424. If you try to use any of these ports, you won't be able to publish your service, and one of the following error messages will appear in the activity log for Windows Azure:
Error validating the .cscfg file against the .csdef file. The reserved port range 'range' for endpoint Microsoft.WindowsAzure.Plugins.RemoteDebugger.Connector of role 'role' overlaps with an already defined port or range.
Allocation failed. Please retry later, try reducing the VM size or number of role instances, or try deploying to a different region.
- Error validating the .cscfg file against the .csdef file. The reserved port range 'range' for endpoint Microsoft.WindowsAzure.Plugins.RemoteDebugger.Connector of role 'role' overlaps with an already defined port or range.
If you redeploy your cloud service without the Deployment update check box selected, you must restart Visual Studio to attach the debugger to the deployed service. This step is required because a full deployment changes the VIP (virtual IP address).
ConceptsDebugging Cloud Services