次の方法で共有


Debugging Overview

Microsoft Silverlight will reach end of support after October 2021. Learn more.

The Silverlight Tools for Visual Studio 2010 include support for debugging Silverlight-based applications. The Silverlight Tools support most managed debugging features. However, it does not support edit-and-continue, just-in-time debugging, and mixed-mode debugging.

For information about the Silverlight Tools for Visual Studio 2010, see Silverlight Tools.

Debugging with Visual Studio

With the Silverlight Tools installed, you can debug Silverlight projects the same way that you would any other project type. When you press F5, Visual Studio will start your application in the default browser and attach the debugger. You can then perform common tasks, such as setting breakpoints and examining the call stack.

Visual Studio 2010 and Silverlight 4 provide additional support for debugging out-of-browser applications. For more information, see Out-of-Browser Support. Silverlight 5 adds support for setting breakpoints on data bindings in XAML. When a breakpoint is hit, you can use the Locals window to examine the state of a binding and pinpoint any issues. For more information, see Data Binding.

For general information about debugging with Visual Studio, see Debugging in Visual Studio.

Attaching the Debugger to a Silverlight Process

With the Silverlight Tools installed, you can also attach the debugger to any local process running a Silverlight-based application in a supported browser or out-of-browser window. The Attach to Process dialog box (on the Debug menu) lists these processes with "Silverlight" in the Type column.

To debug your Silverlight code, attach to the browser process using the default Attach to value of Silverlight. Note that you can debug JavaScript code in the host Web page by using an Attach to value of Script. However, you cannot debug your Silverlight code and your JavaScript code at the same time.

Attaching the Debugger to a Remote Macintosh Process

You can also attach the debugger to a remote Macintosh browser process running a Silverlight-based application. This requires some additional configuration steps on both computers, and is supported only between a computer running Windows and a Macintosh computer. Additionally, when debugging a remote process, the Disassembly and Registers windows are not available.

For more information, see Walkthrough: Setting Up Remote Debugging on the Macintosh.

The Silverlight Debugging API

The native API used to implement Silverlight managed-code debugging is the ICorDebug Interface. Silverlight adds a few new APIs, but otherwise, this is the same API used to implement debuggers for managed applications that use the full .NET Framework. This means that you can extend existing managed-code debuggers to support Silverlight without requiring significant amounts of new code.

For more information, see Silverlight Debugging Overview and Debugging (Unmanaged API Reference). If you have questions regarding the API usage or documentation, see the Building Development and Diagnostic Tools for .NET forum.

Debugging JavaScript in a Silverlight Project

In Visual Studio, you can set breakpoints in your managed Silverlight code and also in JavaScript code within the host Web page. However, as mentioned earlier in this topic, you cannot debug Silverlight code and JavaScript code at the same time.

To debug JavaScript using Internet Explorer, you must first configure the browser to enable script debugging. In Internet Explorer, on the Tools menu, select Internet Options. Then, on the Advanced tab, do the following:

  • Clear the Disable Script Debugging (Internet Explorer) check box

  • Clear the Disable Script Debugging (Other) check box.

  • Select the Display a notification about every script error check box.

  • Clear the Show friendly HTTP error messages check box.

When you use F5 to debug your Silverlight-based application, Visual Studio will attach the Silverlight debugger by default. JavaScript breakpoints will display a ToolTip with the message "The breakpoint will not currently be hit. No symbols have been loaded for this document."

You can debug your JavaScript code in one of two ways:

  • Use CTRL+F5 to start your application without the debugger. You can then attach the debugger to the browser process using the Script code type as described earlier in this topic. After you attach the debugger, you can refresh the browser to reload the Silverlight plug-in. This is necessary to debug your application startup code.

  • When your solution includes a Web project, disable the Silverlight debugger. In Visual Studio, select the Web project, and then on the Project menu, select ProjectName Properties. Then, on the Web tab, in the Debuggers section, clear the Silverlight check box. You can then use F5 to start your application with the script debugger attached.

When the script debugger is attached, the breakpoints in your managed Silverlight code will be disabled.