⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

When a test fails and AssemblyCleanup throws, only the cleanup exception message was visible, hiding the test failure.

[TestClass]
public sealed class Test1
{
    [TestMethod]
    public void TestMethod1()
    {
        Assert.Fail("I want to see this");  // Hidden
    }

    [AssemblyCleanup]
    public static void Shutdown()
    {
        throw new Exception("... but I only see this");  // Only this shown
    }
}

Root Cause

TestResult.TestFailureException setter combines exceptions into AggregateException, but ExceptionHelper formatting methods only traversed InnerException (first exception), not InnerExceptions (all exceptions).

Changes

  • ExceptionHelper.GetFormattedExceptionMessage(): Special-case AggregateException to recursively format all inner exceptions
  • ExceptionHelper.GetStackTraceInformation(): Special-case AggregateException to include all inner stack traces
  • Circular reference protection: Track visited exceptions to prevent infinite recursion
  • Unit tests: Verify AggregateException handling, nesting, and circular references
  • Acceptance test: Reproduce exact scenario from issue

Both test failure and cleanup exception messages now appear in output.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 5rqvsblobprodcus385.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.26077.1.txt (dns block)
    • Triggering command: /home/REDACTED/work/testfx/testfx/.dotnet/dotnet /home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/11.0.0-beta.26077.1.txt 26064.120/productVersion.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>AssemblyCleanup exception hides test failure</issue_title>
<issue_description>An exception in AssemblyCleanup hides test exception

Steps To Reproduce

Run this:

[TestClass]
public sealed class Test1
{
    [TestMethod]
    public void TestMethod1()
    {
        Assert.Fail("I want to see this");
    }

    [AssemblyCleanup]
    public static void Shutdown()
    {
        throw new Exception("... but I only see this");
    }
}

Expected behavior

"I want to see this" should be seen in the output

Actual behavior

but this is the only output:

   ...\MSTestProject1.dll : error TESTERROR: 
      TestMethod1 (140ms): Fehlermeldung: Fehler bei der Methode "Test1.Shutdown" für die Assemblybereinigung. Fehlermeldung: System.Exception: ... but I only see this. "StackTrace":     bei MSTestPro
      ject1.Test1.Shutdown() in ...\MSTestProject1\Test1.cs:Zeile 15.
      
      Stapelverfolgung:
         bei Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestAssemblyInfo.ExecuteAssemblyCleanup() in /_/src/Adapter/MSTest.TestAdapter/Execution/TestAssemblyInfo.cs:Zeile 316.
         bei Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner.RunAssemblyCleanupIfNeeded(ITestContext testContext, ClassCleanupManager classCleanupManager, TypeCache typ
```</issue_description>

<agent_instructions>Fix code and add unit test and acceptance test for that</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@Youssef1313</author><body>
This is the right repo.</body></comment_new>
<comment_new><author>@Youssef1313</author><body>
Which version of MSTest are you using? Did you try the latest version?</body></comment_new>
<comment_new><author>@Youssef1313</author><body>
This is likely already fixed by https://github.com/microsoft/testfx/pull/5505 (MSTest 3.9.0 and later - it's recommended to be on the latest MSTest 4.x)</body></comment_new>
<comment_new><author>@Youssef1313</author><body>
This is mostly .NET Framework behavior where `AggregateException` doesn't override `Message` to include the message of all inner exceptions. We can try to adjust for this.</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 29, 2026 11:15
Copilot AI changed the title [WIP] Fix AssemblyCleanup exception hiding test failures Fix AssemblyCleanup exception hiding test failure Jan 29, 2026
Copilot AI requested a review from Evangelink January 29, 2026 11:22
@Evangelink Evangelink closed this Jan 29, 2026
@Evangelink Evangelink deleted the copilot/fix-assemblycleanup-exception branch January 29, 2026 18:41
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.

AssemblyCleanup exception hides test failure

2 participants