Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Sep 24, 2025

This reverts the behavior to .NET Framework - there is now nothing to prevent the handlers from being called
multiple times.

Fixes #119968
Fixes #119731

Replaces #119734

/cc @janvorli

This reverts the behavior to .NET Framework - there is now
nothing to prevent the handlers from being called
multiple times.
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Sep 24, 2025
Copilot AI review requested due to automatic review settings September 24, 2025 21:14
Copy link
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 reverts the unhandled exception logic in .NET to match .NET Framework behavior by removing safeguards that prevented multiple calls to unhandled exception handlers. The change removes thread-based protection that was preventing handlers from being called multiple times when unhandled exceptions occur.

Key changes:

  • Removed thread ID tracking logic that prevented multiple unhandled exception handler calls
  • Simplified the OnUnhandledException method by removing concurrency control
  • Updated test cleanup code to remove references to the removed static field

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.CoreLib/src/System/AppContext.cs Removed thread ID tracking and protection logic from OnUnhandledException method
src/tests/baseservices/exceptions/RaiseAppDomainUnhandledExceptionEvent/RaiseEvent.cs Removed test cleanup code and UnsafeAccessor usage for the removed static field

@AaronRobinsonMSFT
Copy link
Member Author

This needs to be ported to .NET 10.

Copy link
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.

Thanks

@AaronRobinsonMSFT
Copy link
Member Author

/backport to release/10.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/10.0-rc2: https://github.com/dotnet/runtime/actions/runs/17996189425

@agocke
Copy link
Member

agocke commented Sep 25, 2025

/backport to release/10.0

@github-actions
Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18015789538

@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled exception can only be unwound once in .NET 10 rc1 Check for recursion in calls to AppContext.OnUnhandledException is incorrect

4 participants