Skip to content

Fix race in WeakEventProxy field access - #37568

Merged
kubaflo merged 1 commit into
dotnet:inflight/currentfrom
baaaaif:fix/weak-event-proxy-race
Aug 18, 2026
Merged

kubaflo merged 1 commit into
dotnet:inflight/currentfrom
baaaaif:fix/weak-event-proxy-race

Conversation

@baaaaif

@baaaaif baaaaif commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description of Change

Captures the weak-reference fields in local variables before testing and dereferencing them. This closes the time-of-check/time-of-use race with Unsubscribe(), which clears the fields concurrently.

The race has been observed as an unhandled Android NullReferenceException from both TryGetSource during binding finalization and TryGetHandler while processing property changes.

Issues Fixed

Fixes #32602

Validation

  • dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore --verbosity minimal -p:TargetFramework=netstandard2.0

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@baaaaif
baaaaif temporarily deployed to copilot-pat-pool August 18, 2026 07:59 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37568

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37568"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@baaaaif! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @baaaaif! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@baaaaif
baaaaif temporarily deployed to copilot-pat-pool August 18, 2026 08:00 — with GitHub Actions Inactive
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Capturing the weak-reference fields in locals makes each check/use operate on a single reference. This closes the race where Unsubscribe() can null the field between the two field reads, while preserving the existing weak-reference semantics. The linked TryGetSource/TryGetHandler stack traces are consistent with this failure. Looks good to me.

@kubaflo
kubaflo changed the base branch from main to inflight/current August 18, 2026 13:24
@kubaflo
kubaflo merged commit b60e6ee into dotnet:inflight/current Aug 18, 2026
9 of 11 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Aug 18, 2026
kubaflo pushed a commit that referenced this pull request Aug 27, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 2, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
### Description of Change

Captures the weak-reference fields in local variables before testing and
dereferencing them. This closes the time-of-check/time-of-use race with
`Unsubscribe()`, which clears the fields concurrently.

The race has been observed as an unhandled Android
`NullReferenceException` from both `TryGetSource` during binding
finalization and `TryGetHandler` while processing property changes.

### Issues Fixed

Fixes #32602

### Validation

- `dotnet build src/Controls/src/Core/Controls.Core.csproj --no-restore
--verbosity minimal -p:TargetFramework=netstandard2.0`

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 18, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — ee9c4e29 Deployed Aug 18, 2026 by baaaaif via conclusion #1401
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException at BindingExpression

2 participants