Debugging Expression Blend applications in Visual Studio 2005
- To step through your code line by line
- To debug a XAML Browser application (XBAP) application
- To debug runtime XAML errors in Visual Studio 2005
- General debugging
Expression Blend is a design tool for creating rich Microsoft Windows® applications that make use of WPF features. Visual Studio 2005, which is also used to build Microsoft Windows applications, can open, build, and debug Expression Blend projects. If you are having trouble debugging your application using the Test (F5) feature of Expression Blend, you can use Visual Studio 2005 to obtain detailed error messages about runtime errors. Sometimes, you can fix runtime errors by trying out different changes in your XAML or code until you understand what is going on behind the scenes. However, it is faster to actually watch what is going on behind the scenes by stepping through your code line by line as the application is running.
To step through your code line by line
- Open your Expression Blend project in Visual Studio 2005.
- Click on a line of code that you are interested in and set a breakpoint by
pressing F9. If you want to step through your code starting at the beginning,
set the breakpoint at the line
this.InitializeComponent();in the Window1.xaml.cs file.
- Press F5 to start your application.
Visual Studio will build and run your application until the line with the breakpoint is called. At that point, application execution stops and Visual
Studio 2005 displays the file that contains the breakpoint, and displays a yellow arrow at the line that is about to be executed.
- Under the Debug menu, there are three options for stepping
- Step Into (F11) will execute the next line of code, and if that line is a function call, it will take you to the first line in that function call.
- Step Over (F10) will also execute the next line of code, but if that line is a function call, it will execute that function and take you to the next line after the function call.
- Step Out (SHIFT+F11) will bring you out of a function call.
- In the Locals panel, you can see what variables are currently instantiated, and what values they contain. As you step through code, the values of variables in the Locals panel are updated. This can help you debug your application if you suspect that a loop is not being called as many times as you expect it to be called, or if you suspect a variable does not contain a value that you expect, or if a variable disappears (goes out of scope) before it is needed.
To debug a XAML Browser application (XBAP) application
To debug a XAML Browser application (XBAP) application while it runs in a browser, you need to use the Attach to Process feature of Visual Studio 2005 Standard Edition or higher. Use the following procedure:
- From the command line, type the following line and press ENTER.
This starts the WPF process in debug mode.
- In Visual Studio 2005, open your XBAP project.
- In the Project menu, click Properties. In the Debug tab, select Enable unmanaged code debugging. Close the properties window.
- In the Debug menu, click the Attach to Process.
- In the Attach to Process window, next to Attach to, click Select. Under Debug these code types, select Managed and Native, and click OK. Under Available Processes, select PresentationHost.exe. Click Attach to start debugging.
- In Windows Explorer, double-click the .xbap file for you application in the
bin\Debug folder of your project.
Your application will launch in your default browser. If you have set any breakpoints, then application execution will stop and Visual
Studio 2005 will display the file that contains the breakpoint, and display a yellow arrow at the line that is about to be executed. From here, you can step through code as normal.
|To create new XAML applications and XAML Browser applications (XBAPs) in Visual Studio 2005, you need to install the extensions for .NET Framework 3.0. These can be downloaded from MSDN. (You do not need the extensions to debug XAML applications that were created with Expression Blend.)|
To debug runtime XAML errors in Visual Studio 2005
If you have a XAML error that is occurring at runtime, you can get
information about which line of XAML is causing the error by adding the following line to your project file (.csproj or
.vbproj) in the
This project file property is only set to true by default in the debug version of your build because it increases the size of your application.
It can be difficult to understand what is causing a bug or where it exists in your application, but it helps to understand the types of bugs that you might encounter. For more information, see the topic Debugging Expression Blend applications in this User Guide.