Fix CS8603 error for nullable reference types in SourceGen binding paths#32480
Merged
StephaneDelcroix merged 4 commits intomainfrom Nov 11, 2025
Merged
Fix CS8603 error for nullable reference types in SourceGen binding paths#32480StephaneDelcroix merged 4 commits intomainfrom
StephaneDelcroix merged 4 commits intomainfrom
Conversation
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
When binding path contains conditional access to a nullable object followed by a reference type property (e.g., source.NullableObject?.StringProperty where StringProperty is string?), the property type now correctly includes nullable annotation. This prevents CS8603 "Possible null reference return" errors in generated binding code.
The fix ensures reference types with conditional access in the path are marked as nullable in the TypedBinding signature, while preserving the existing behavior for value types (which use ?? default fallback).
Fixes issue where XAML bindings like <Entry Text="{Binding SomeNullableObject.SomeStringProperty}"/> would generate code with CS8603 errors when SomeNullableObject is nullable and SomeStringProperty is a nullable reference type.
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error CS8603 for nullable object in SourceGen
Fix CS8603 error for nullable reference types in SourceGen binding paths
Nov 10, 2025
src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs
Show resolved
Hide resolved
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs
Outdated
Show resolved
Hide resolved
src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs
Outdated
Show resolved
Hide resolved
- Changed StringProperty from nullable (string?) to non-nullable (string) in test cases - the nullability comes from NullableObject being nullable, not the property itself - Removed WriteLine debugging statements from tests - Converted CorrectlyDetectsNullableReferenceTypes test to a snapshot test with full expected output - Split combined assertions into separate asserts for better test clarity - Removed unnecessary blank lines from expected output formatting - Updated setter expectations to include null check when property is non-nullable Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Member
|
/azp run |
simonrozsival
approved these changes
Nov 10, 2025
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes CS8603 errors in SourceGen-generated code when binding to nullable reference types through a nullable path (e.g., source.SomeNullableObject?.SomeStringProperty).
Key Changes:
- Fixed bug in
CompiledBindingMarkup.cswhere nullable annotation was being overwritten - Added comprehensive test coverage for nullable reference types in binding paths
- Tests verify both the generated code structure and absence of CS8603 errors
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Controls/src/SourceGen/CompiledBindingMarkup.cs |
Fixed nullable annotation logic by moving assignment before annotation |
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs |
Added snapshot test and error verification test for nullable reference types |
src/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs |
Added integration tests for SetBinding and Create with nullable paths |
StephaneDelcroix
approved these changes
Nov 11, 2025
This was referenced Nov 18, 2025
|
Is this part of the latest .NET release today? |
This was referenced Dec 16, 2025
Merged
This was referenced Dec 18, 2025
evgenygunko
pushed a commit
to evgenygunko/CopyWordsDA
that referenced
this pull request
Dec 18, 2025
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Microsoft.Maui.Controls](https://github.com/dotnet/maui) | nuget | patch | `10.0.11` -> `10.0.20` | --- ### Release Notes <details> <summary>dotnet/maui (Microsoft.Maui.Controls)</summary> ### [`v10.0.20`](https://github.com/dotnet/maui/releases/tag/10.0.20): SR2 [Compare Source](dotnet/maui@10.0.11...10.0.20) ##### What's Changed **Note:** This is a service release (SR2) tracking ongoing release/10.0.1xx-sr2 branch development. The version number 10.0.20 represents the second service release for .NET MAUI 10. .NET MAUI 10.0.20 development introduces significant improvements across all platforms with focus on quality, performance, and developer experience. Current development includes enhancements to XAML Source Generator, iOS/macOS fixes, AppThemeBinding improvements, and improved developer tooling. ##### AI - PR Reviewer Agent by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32340 - \[AI] The Issue-Resolver agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32804 - \[AI] Fixed links for agents by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32818 - Add checkpoint/resume system for PR review agent by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32774 - Improved pr-reviewer AI agent and modified the usage instructions in README by [@​kubaflo](https://github.com/kubaflo) in dotnet/maui#32718 - Agents scripts by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32819 - Simplify agent instructions and consolidate sandbox testing workflow by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32950 ##### Brushes - Fix SolidColorBrush.Equals to compare Color values instead of references by [@​StephaneDelcroix](https://github.com/StephaneDelcroix) in dotnet/maui#32956 <details> <summary>🔧 Fixes</summary> - [Using DynamicResource with OnPlatform<Color> causes infinite loop](dotnet/maui#27281) </details> ##### Data Binding - Fix CS8603 error for nullable reference types in SourceGen binding paths by [@​Copilot](https://github.com/Copilot) in dotnet/maui#32480 <details> <summary>🔧 Fixes</summary> - [error CS8603: Possible null reference return in generated code using SourceGen](dotnet/maui#32478) </details> ##### Docs - Add README-AI.md file by [@​PureWeen](https://github.com/PureWeen) in dotnet/maui#32502 - Improve AI agent documentation and testing instructions by [@​Copilot](https://github.com/Copilot) in https://github.com/dotnet/maui/p...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Implemented and Tested - Review Feedback Addressed
Issue Analysis:
source.SomeNullableObject.SomeStringPropertywhereSomeNullableObjectis nullable andSomeStringPropertyis a reference type, the generated code produces CS8603 errorCompiledBindingMarkup.csin theTryParsePathmethod (lines 410-422)previousPartTypeFix Applied:
propertyType = previousPartTypeassignmentReview Feedback Addressed:
StringPropertyfromstring?tostringin test cases (nullability comes from nullable object, not the property)Testing:
Files modified:
src/Controls/src/SourceGen/CompiledBindingMarkup.cs- Fixed nullable annotation logicsrc/Controls/tests/BindingSourceGen.UnitTests/IntegrationTests.cs- Updated test cases per review feedbacksrc/Controls/tests/SourceGen.UnitTests/InitializeComponent/CompiledBindings.cs- Updated test cases per review feedbackOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.