Sunday, 1 May 2011

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 theDebuggers 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.

No comments:

Post a Comment