Skip to content

Fix warning when using nullable properties in ValidationMessageStore.Add field accessor#66901

Open
BharatRamsf3693 wants to merge 26 commits into
dotnet:mainfrom
BharatRamsf3693:main
Open

Fix warning when using nullable properties in ValidationMessageStore.Add field accessor#66901
BharatRamsf3693 wants to merge 26 commits into
dotnet:mainfrom
BharatRamsf3693:main

Conversation

@BharatRamsf3693

@BharatRamsf3693 BharatRamsf3693 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Fix warning when using nullable properties in ValidationMessageStore.Add field accessor

Description

This PR adds fix and test cases to ensure that ValidationMessageStore.Add correctly supports nullable properties when using expression-based field accessors.
Previously, using ValidationMessageStore.Add with a nullable property (for example, string?) could result in compiler nullability warnings due to overload resolution choosing the non-generic Expression<Func> overload, which requires boxing and leads to mismatched nullability expectations.

This change verifies that the generic overload Add(Expression<Func> accessor, ...) is correctly selected, allowing TField to be inferred as a nullable type (e.g., string?). As a result:

  1. Nullable properties can be used without compiler warnings.
  2. Behavior is consistent for both single and multiple validation messages.
  3. The API provides a better developer experience in nullable-enabled projects.

Before

image

After

image

The added tests cover:

  1. Adding a single validation message using a nullable property expression
  2. Adding multiple validation messages using a nullable property expression

Fixes #41338

@BharatRamsf3693 BharatRamsf3693 requested a review from a team as a code owner May 29, 2026 10:08
@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label May 29, 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 29, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@BharatRamsf3693

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree company="Syncfusion, Inc."

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.

ValidationMessageStore.Add field accessor parameter shows a warning for nullable properties

1 participant