Skip to content

Fix nullable annotation for ElementReference.Id#66645

Open
sheiksyedm wants to merge 6 commits into
dotnet:mainfrom
sheiksyedm:fix/elementreference-nullable-id
Open

Fix nullable annotation for ElementReference.Id#66645
sheiksyedm wants to merge 6 commits into
dotnet:mainfrom
sheiksyedm:fix/elementreference-nullable-id

Conversation

@sheiksyedm

@sheiksyedm sheiksyedm commented May 11, 2026

Copy link
Copy Markdown

Summary

ElementReference is a struct, so it can be initialized via the parameterless constructor (new ElementReference()) or default(ElementReference), both of which leave Id as null. The current non-nullable annotation (string) is incorrect and causes false analyzer warnings when users write null-safe code.

Changes

  • Changed ElementReference.Id from string to string?
  • Updated PublicAPI.Shipped.txt to reflect the corrected nullability

Impact

This is a metadata-only change (nullable annotation). No runtime behavior is affected. Users who already handle null correctly will no longer see suppression warnings, and those who don't will now get proper compiler guidance.

Fixes #58523

ElementReference is a struct that can be initialized via parameterless
constructor or default(), leaving Id as null. Mark Id as string? to
correctly reflect this possibility.

Fixes dotnet#58523
Copilot AI review requested due to automatic review settings May 11, 2026 14:11
@sheiksyedm sheiksyedm requested review from a team and tdykstra as code owners May 11, 2026 14:11
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label May 11, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @sheiksyedm. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot AI 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.

Pull request overview

Corrects the nullable annotation of Microsoft.AspNetCore.Components.ElementReference.Id to reflect that ElementReference is a struct and may be default-initialized with Id == null, reducing false nullable-analyzer warnings for consumers.

Changes:

  • Updated ElementReference.Id from string to string?.
  • Updated PublicAPI.Shipped.txt to reflect the corrected nullability metadata.

Reviewed changes

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

File Description
src/Components/Components/src/ElementReference.cs Updates Id nullability to match default(struct) behavior.
src/Components/Components/src/PublicAPI.Shipped.txt Updates shipped API metadata for the Id getter nullability.

Comment thread src/Components/Components/src/ElementReference.cs
Comment thread src/Components/Components/src/ElementReference.cs
This reverts commit 1aa67cb.
PublicAPI.Shipped.txt must not be modified directly. Use *REMOVED* +
new entry pattern in Unshipped.txt per docs/APIBaselines.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ElementReference.Id has wrong nullable annotation

2 participants