JetBrains Rider 2025.1 Help

Debug LINQ expressions

When working with LINQ expressions in C#, you can debug them visually with JetBrains Rider, with a clear representation of how data is transformed at each step of the query.

Consider the following example:

using System; using System.Linq; class PrimeFinder { public static void Find() { int skip = 0; int limit = 100; var result = Enumerable.Range(1, int.MaxValue) .Skip(skip) .Take(limit) .Where(IsPrime) .ToList(); foreach (var prime in result) { Console.WriteLine(prime); } } private static bool IsPrime(int candidate) { return candidate == 91 || // Bug here Enumerable.Range(2, (int)Math.Sqrt(candidate)) .All(n => candidate % n != 0); } }

Let’s use the Rider LINQ debugging feature to analyze the LINQ expression step by step.

  1. Suspend the program execution at the LINQ expression by setting a breakpoint on the line:

    var result = Enumerable.Range(1, int.MaxValue) // Breakpoint here .Skip(skip) .Take(limit) .Where(IsPrime) .ToList();
  2. When execution is paused at the breakpoint, you’ll notice the Explore LINQ inlay hint displayed above the LINQ expression:

  3. Click Explore LINQ to open the LINQ visualizer. Rider will display a detailed breakdown of how data flows through each step of the LINQ chain in a dialog:

    LINQ visualization popup in Rider.
  4. Use this visualization to see how the data changes at each stage:

    • Range: The initial sequence generated by Enumerable.Range.

    • Skip: How many items are skipped by the Skip method.

    • Take: The subset of items selected by Take.

    • Where: Items filtered based on the IsPrime method.

  5. Analyze the intermediate results step by step to uncover issues. For example, in this code, you’ll notice that the number 91 is included in the results, which points to the error in the IsPrime method.

The Explore LINQ feature is especially helpful for debugging complex LINQ queries by making their transformations visible and comprehensible at a glance.

Enable the LINQ Debugger plugin

This functionality relies on the LINQ Debugger plugin, which is bundled and enabled in JetBrains Rider by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the LINQ Debugger plugin, and select the checkbox next to the plugin name.

Last modified: 31 March 2025