C#idiomatic C#
debugging-expression-trees-in-visual-studiocsharp/advanced-topics/expression-trees

Advanced

Debugging expression trees in Visual Studio

Learn about the DebugView property in Visual Studio. See how to use this property to analyze the structure and content of expression trees.

  • page csharp/advanced-topics/expression-trees/debugging-expression-trees-in-visual-studio
  • updated 03/06/2023

You can analyze the structure and content of expression trees when you debug your applications. To get a quick overview of the expression tree structure, you can use the DebugView property, which represents expression trees using a special syntax. DebugView is available only in debug mode.

Screenshot of the DebugView of an expression tree within VS debugger.

Since DebugView is a string, you can use the built-in Text Visualizer to view it across multiple lines, by selecting Text Visualizer from the magnifying glass icon next to the DebugView label.

Screenshot of the Text Visualizer applied to results of DebugView.

Alternatively, you can install and use a custom visualizer for expression trees, such as:

Screenshot of the Readable Expressions visualizer.

Screenshot of the Expression Tree Visualizer.

Open a visualizer for an expression tree

Select the magnifying glass icon that appears next to the expression tree in DataTips, a Watch window, the Autos window, or the Locals window. A list of available visualizers is displayed:

Screenshot showing the Opening of visualizers from Visual Studio.

Select the visualizer you want to use.

See also