IEnumerable Visualizer in Visual Studio 2022: bounding large lazy collections without re-executing IQueryable queries
0 reputation · 29 Jul 2026, 11:47 UTC
0 reputation · 29 Jul 2026, 11:47 UTC
Since Visual Studio 2022 (17.x), the IEnumerable Visualizer opens collections in a sortable, filterable grid that loads rows incrementally, instead of forcing one-by-one expansion in the Watch window. Our team is moving debugging habits from DebuggerDisplay/DebuggerTypeProxy attributes toward this visualizer for inspecting large in-memory datasets.
Many of our enumerables are LINQ over IQueryable backed by a database. Because debugger evaluation runs inside the debugged process, we are unsure whether filtering or scrolling in the visualizer re-executes the underlying query, changes timing, or triggers exceptions that would not occur at that point in normal execution. The attribute-based approach is version-stable but requires code changes and careful side-effect avoidance; the visualizer requires none but is less predictable for lazy sequences.
IQueryable?ToList() in the debugged process?DebuggerTypeProxy still the recommended option over the visualizer in current Visual Studio 2022 builds?35275 reputation · 29 Jul 2026, 16:04 UTC
GetEnumerator()/MoveNext(). For an IQueryable source this usually means the underlying query is re‑executed unless the provider itself caches results.Take(n) (or Skip/Take) to the variable in the watch expression before opening the visualizer.DebuggerTypeProxy (or materialize with ToList()) because the visualizer may re‑enumerate and repeat those effects.When the visualizer needs additional rows it calls the enumerable’s GetEnumerator again. For lazy LINQ over IQueryable each call creates a new query execution unless the provider (e.g., EF Core with tracking disabled) caches the results internally. Hence filtering or scrolling can trigger repeated database round‑trips.
myQuery.Take(50).DebuggerTypeProxy to the type or materialize with ToList() in the debugged process.Whether your IQueryable provider caches results (e.g., EF Core AsNoTracking vs. tracked queries) changes the impact of re‑enumeration. If the provider caches, repeated visualizer enumerations may not re‑execute the query; if it does not, each scroll will cause a new database round‑trip. Confirm the caching behavior of your provider to decide if additional bounding is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.