Content Index Search

Debugging Expression Blend applications in Visual Studio 2005

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

  1. Open your Expression Blend project in Visual Studio 2005.
  2. 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.
  3. 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.
  4. Under the Debug menu, there are three options for stepping through code:
    • 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.
    The most common option you will use is Step Over (F10). While you step through the code, you can see what code paths are being executed and if code is not being executed in the order that you expected.
  5. 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:

  1. From the command line, type the following line and press ENTER.
         %SystemRoot%\system32\PresentationHost.exe -debug
    This starts the WPF process in debug mode.
  2. In Visual Studio 2005, open your XBAP project.
  3. In the Project menu, click Properties. In the Debug tab, select Enable unmanaged code debugging. Close the properties window.
  4. In the Debug menu, click the Attach to Process.
  5. 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.
  6. 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.
Tip 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.)

For more information about debugging, see Debugging in Visual Studio 2005 on MSDN.

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 <PropertyGroup> section:


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.

General debugging

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.