Debug Expression Blend applications in Visual Studio 2008

Microsoft Expression Blend is a design application for creating rich Windows Presentation Foundation (WPF) applications for Microsoft Windows, and Microsoft Silverlight applications for the web. Microsoft Visual Studio 2008, 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 Run Project (F5) feature of Expression Blend, you can use Visual Studio 2008 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 2008.

  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 2008 will build and run your application until the line with the breakpoint is called. At that point, application execution stops and Visual Studio 2008 displays the file that contains the breakpoint, and displays a yellow arrow at the line that is about to be executed.

  4. On 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 whether 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 WPF Browser Application

To debug a WPF Browser Application while it runs in a browser, you have to use the Attach to Process feature of Visual Studio 2008 Standard Edition or higher. Use the following procedure.

  1. Build and run your project at least once to create debug files.

  2. From the command line, type the following line and press ENTER.

    %SystemRoot%\system32\PresentationHost.exe -debug

    This starts the WPF process in debug mode.

  3. In Visual Studio 2008, open your WPF Browser Application project.

  4. In the Project menu, click Properties. On the Debug tab, select Enable unmanaged code debugging. Close the properties window.

  5. In the Debug menu, click the Attach to Process.

  6. 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 AvailableProcesses, select PresentationHost.exe. Click Attach to start debugging.

  7. In Windows Explorer, double-click the .xbap file for you application in the bin\Debug folder of your project.

  8. Your application will launch in your default browser. If you have set any breakpoints, then application execution will stop and Visual Studio 2008 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.

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

To debug runtime XAML errors in Visual Studio 2008

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 Debug Expression Blend applications.