Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 28, 2025

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 DEBUG conditionals as a workaround.

Root Cause

The issue was that VSTest's testhost.exe.config includes a critical AppContext switch:

<AppContextSwitchOverrides value="Switch.System.Diagnostics.IgnorePortablePDBsInStackTraces=false" />

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

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

  2. Test Fixes: Systematically removed #if DEBUG conditionals from stack trace validation tests, including:

    • Critical test infrastructure in CLITestBase.e2e.cs used throughout the test suite
    • Unit tests in TestAssemblyInfoTests, TestMethodInfoTests, and TestClassInfoTests
    • Re-enabled integration tests that were disabled due to stack trace issues

Validation

Manual testing confirmed that:

  • Stack traces are now generated correctly in release builds
  • The AppContext switch works as expected with portable PDBs
  • Previously failing stack trace assertions now pass in both debug and release modes

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.

Copilot AI changed the title [WIP] Investigate why stacktrace are empty in release mode Fix empty stack traces in release mode when using Microsoft Testing Platform Jul 28, 2025
Copilot AI requested a review from Evangelink July 28, 2025 10:12
@Evangelink Evangelink mentioned this pull request Jul 28, 2025
@Evangelink Evangelink closed this Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate why stacktrace are empty in release mode

2 participants