Skip to content

Disable EnsureEnvironmentExitDoesntHang on .NET Framework#125912

Merged
danmoseley merged 2 commits intomainfrom
copilot/fix-console-lifetime-exit-test
Mar 23, 2026
Merged

Disable EnsureEnvironmentExitDoesntHang on .NET Framework#125912
danmoseley merged 2 commits intomainfrom
copilot/fix-console-lifetime-exit-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang fails on .NET Framework because System.Console.ControlCHooker.Unhook() throws IOException: The parameter is incorrect during process finalization, causing an unhandled exception (exit code -532462766 / EXCEPTION_COMPLUS). This is a known .NET Framework shutdown limitation.

Changes

  • Added [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NET Framework shutdown issue")] to EnsureEnvironmentExitDoesntHang — consistent with the existing skip on the related EnsureEnvironmentExitCode test
  • Simplified the test body: removed the now-dead expectedExitCode = PlatformDetection.IsNetFramework ? 0 : 125 conditional, inlining 125 directly

Note

This PR description was generated with AI assistance (GitHub Copilot).

Original prompt

This section details on the original issue you should resolve

<issue_title>Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang fails on .NET Framework</issue_title>
<issue_description>## Build Information
Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1143743
Build error leg or test failing: Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang
Pull request: #119515

Console excerpt:

    Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL]
      Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code was -532462766 but it should have been 0
      Stack Trace:
        /_/src/arcade/src/Microsoft.DotNet.RemoteExecutor/src/RemoteInvokeHandle.cs(242,0): at Microsoft.DotNet.RemoteExecutor.RemoteInvokeHandle.Dispose(Boolean disposing)
        /_/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeExitTests.cs(223,0): at Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang()

-532462766 corresponds with EXCEPTION_COMPLUS.

{
  "ErrorMessage": "ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL]",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
Error message validated: [Microsoft\.DotNet\.RemoteExecutor\.RemoteExecutionException : Exit code was -532462766 but it should have been 0.*EnsureEnvironmentExitDoesntHang()]
Result validation: ❌ Known issue did not match with the provided build.
Validation performed at: 9/10/2025 6:12:29 PM UTC

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
Error message validated: [Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code was -532462766 but it should have been 0]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 9/10/2025 7:05:39 PM UTC

Report

Build Definition Test Pull Request
1143743 dotnet/runtime Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang #119515

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
1 1 1

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
Error message validated: [at System.Console.ControlCHooker.Unhook]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 9/10/2025 7:07:38 PM UTC

Report

Build Definition Test Pull Request
1143743 dotnet/runtime Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang #119515

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
1 1 1

Report

Build Definition Test Pull Request
1174378 dotnet/runtime Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang
1170349 dotnet/runtime Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang #120603
1169444 dotnet/runtime [Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitT...

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Fix EnsureEnvironmentExitDoesntHang test for .NET Framework Disable EnsureEnvironmentExitDoesntHang on .NET Framework Mar 22, 2026
Copilot AI requested a review from danmoseley March 22, 2026 04:33
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

@danmoseley danmoseley marked this pull request as ready for review March 22, 2026 05:11
Copilot AI review requested due to automatic review settings March 22, 2026 05:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR disables ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang when running on .NET Framework due to a known shutdown/finalization limitation that can cause an unhandled exception during process teardown, making the test unreliable in that target.

Changes:

  • Added a .NET Framework-specific skip to EnsureEnvironmentExitDoesntHang.
  • Simplified the expected exit code logic by inlining the non-.NET-Framework expected exit code (125).

@danmoseley danmoseley requested review from adamsitnik and jkotas and removed request for adamsitnik March 22, 2026 05:44
@jkotas jkotas requested review from a team and mrek-msft March 22, 2026 17:59
Copy link
Copy Markdown
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

cc @dotnet/area-extensions-hosting @mrek-msft for awareness

@danmoseley danmoseley enabled auto-merge (squash) March 22, 2026 20:27
@danmoseley
Copy link
Copy Markdown
Member


Assert.True() Failure
Expected: True
Actual:   False



Stack trace
   at Microsoft.Extensions.Hosting.Internal.HostTests.<StartCanBeCancelled>d__13.MoveNext() in /_/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs:line 297
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

@danmoseley danmoseley disabled auto-merge March 23, 2026 00:53
@danmoseley danmoseley merged commit 982dc8a into main Mar 23, 2026
88 of 90 checks passed
@danmoseley danmoseley deleted the copilot/fix-console-lifetime-exit-test branch March 23, 2026 03:00
eiriktsarpalis pushed a commit that referenced this pull request Mar 23, 2026
`ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang` fails on .NET
Framework because `System.Console.ControlCHooker.Unhook()` throws
`IOException: The parameter is incorrect` during process finalization,
causing an unhandled exception (exit code -532462766 /
EXCEPTION_COMPLUS). This is a known .NET Framework shutdown limitation.

## Changes

- Added `[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework,
"NET Framework shutdown issue")]` to `EnsureEnvironmentExitDoesntHang` —
consistent with the existing skip on the related
`EnsureEnvironmentExitCode` test
- Simplified the test body: removed the now-dead `expectedExitCode =
PlatformDetection.IsNetFramework ? 0 : 125` conditional, inlining `125`
directly

> [!NOTE]
> This PR description was generated with AI assistance (GitHub Copilot).

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>


----

*This section details on the original issue you should resolve*


<issue_title>Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang
fails on .NET Framework</issue_title>
<issue_description>## Build Information
Build:
https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1143743
Build error leg or test failing:
Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang
Pull request: #119515

Console excerpt:
```
    Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL]
      Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code was -532462766 but it should have been 0
      Stack Trace:
        /_/src/arcade/src/Microsoft.DotNet.RemoteExecutor/src/RemoteInvokeHandle.cs(242,0): at Microsoft.DotNet.RemoteExecutor.RemoteInvokeHandle.Dispose(Boolean disposing)
        /_/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeExitTests.cs(223,0): at Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang()
```

-532462766 corresponds with EXCEPTION_COMPLUS.

```json
{
  "ErrorMessage": "ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL]",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}
```

<!-- Known issue validation start -->
 ### Known issue validation
**Build: 🔎**
https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
**Error message validated:**
`[Microsoft\.DotNet\.RemoteExecutor\.RemoteExecutionException : Exit
code was -532462766 but it should have been
0.*EnsureEnvironmentExitDoesntHang()`]
**Result validation:** ❌ Known issue did not match with the provided
build.
**Validation performed at:** 9/10/2025 6:12:29 PM UTC
<!-- Known issue validation end -->
<!-- Known issue validation start -->
 ### Known issue validation
**Build: 🔎**
https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
**Error message validated:**
`[Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code
was -532462766 but it should have been 0`]
**Result validation:** ✅ Known issue matched with the
provided build.
**Validation performed at:** 9/10/2025 7:05:39 PM UTC
<!-- Known issue validation end -->
<!--Known issue error report start -->

### Report

|Build|Definition|Test|Pull Request|
|---|---|---|---|

|[1143743](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743&view=ms.vss-test-web.build-test-results-tab&runId=31540798&resultId=103521)|dotnet/runtime#119515|
#### Summary
|24-Hour Hit Count|7-Day Hit Count|1-Month Count|
|---|---|---|
|1|1|1|
<!--Known issue error report end -->
<!-- Known issue validation start -->
 ### Known issue validation
**Build: 🔎**
https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743
**Error message validated:** `[at System.Console.ControlCHooker.Unhook`]
**Result validation:** ✅ Known issue matched with the
provided build.
**Validation performed at:** 9/10/2025 7:07:38 PM UTC
<!-- Known issue validation end -->
<!--Known issue error report start -->

### Report

|Build|Definition|Test|Pull Request|
|---|---|---|---|

|[1143743](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743&view=ms.vss-test-web.build-test-results-tab&runId=31540798&resultId=103521)|dotnet/runtime#119515|
#### Summary
|24-Hour Hit Count|7-Day Hit Count|1-Month Count|
|---|---|---|
|1|1|1|
<!--Known issue error report end -->
<!--Known issue error report start -->

### Report

|Build|Definition|Test|Pull Request|
|---|---|---|---|

|[1174378](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1174378)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1174378&view=ms.vss-test-web.build-test-results-tab&runId=32501172&resultId=104197)||

|[1170349](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1170349)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1170349&view=ms.vss-test-web.build-test-results-tab&runId=32385630&resultId=103595)|dotnet/runtime#120603|

|[1169444](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1169444)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitT...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #119545

<!-- START COPILOT CODING AGENT TIPS -->
---

⌨️ Start Copilot coding agent tasks without leaving your editor —
available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual
Studio](https://gh.io/cca-visual-studio-docs), [JetBrains
IDEs](https://gh.io/cca-jetbrains-docs) and
[Eclipse](https://gh.io/cca-eclipse-docs).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang fails on .NET Framework

5 participants