Fix empty stack traces in release mode when using Microsoft Testing Platform #6196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Stack traces were empty or null in release mode when using Microsoft Testing Platform (MTP), causing test assertions that validate stack trace content to fail. This forced tests to be wrapped with
#if DEBUGconditionals as a workaround.Root Cause
The issue was that VSTest's testhost.exe.config includes a critical AppContext switch:
This setting allows portable PDBs to be used for stack traces. When this switch is not set (default is
true), portable PDBs are ignored and stack traces appear empty in release builds. Microsoft Testing Platform didn't set this AppContext switch, causing the discrepancy between debug and release behavior.Solution
Core Fix: Added
AppContext.SetSwitch("Switch.System.Diagnostics.IgnorePortablePDBsInStackTraces", false)to the TestApplication static constructor in Microsoft.Testing.Platform. This ensures portable PDBs are used for stack traces, matching VSTest behavior.Test Fixes: Systematically removed
#if DEBUGconditionals from stack trace validation tests, including:CLITestBase.e2e.csused throughout the test suiteValidation
Manual testing confirmed that:
The fix is minimal, targeted, and ensures consistent behavior between debug and release builds while matching the established VSTest behavior.
Fixes #5109.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.