Export (0) Print
Expand All

Debug Expression Blend applications in Visual Studio 2008

Microsoft Expression Blend 2 is a design tool for creating rich Windows Presentation Foundation applications for Microsoft Windows, and Microsoft Silverlight 1.0 applications for the web. Microsoft Visual Studio 2008, which is also used to build Microsoft Windows applications, can open, build, and debug Expression Blend 2 projects. If you are having trouble debugging your application using the Test (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.

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

Cc295138.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

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

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

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

    %SystemRoot%\system32\PresentationHost.exe -debug
    

    This starts the WPF process in debug mode.

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

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

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

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

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

Cc295138.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

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:

<XamlDebuggingInformation>true</XamlDebuggingInformation>

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.

Cc295138.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

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 Debug Expression Blend applications in this User Guide.

Cc295138.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gif Back to top

Community Additions

ADD
Show:
© 2014 Microsoft