[release/10.0] Fix InvalidCastException in OriginalValues.ToObject() with nested nullable complex properties#37703
Draft
Copilot wants to merge 15 commits intorelease/10.0from
Draft
[release/10.0] Fix InvalidCastException in OriginalValues.ToObject() with nested nullable complex properties#37703Copilot wants to merge 15 commits intorelease/10.0from
Copilot wants to merge 15 commits intorelease/10.0from
Conversation
…d nullable complex properties Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…st safety Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix InvalidCastException with complex properties in 10.0.2
Fix InvalidCastException in OriginalValues.ToObject() with nested nullable complex properties
Feb 13, 2026
Member
|
@copilot Update progress by rewriting the PR summary using this template: |
Contributor
Author
... Updated PR description with the requested template format. The issue number placeholder (#XXXXX) should be replaced with the actual issue number when available. |
test/EFCore.Tests/ChangeTracking/Internal/PropertyValuesTest.cs
Outdated
Show resolved
Hide resolved
…e comments Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…complex collections Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
AndriySvyryd
approved these changes
Feb 14, 2026
…s, use NullableComplexProperties Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…complex properties Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
| Assert.Null(original3.Error.InnerError); // This was causing InvalidCastException before the fix | ||
| } | ||
|
|
||
| [ConditionalFact(Skip = "Complex collection with nested nullable complex properties not yet fully supported. Issue #31411")] |
Member
There was a problem hiding this comment.
@copilot Unskip this test and improve the fix to handle this scenario as well.
Try to explore other related scenarios and add more tests
Contributor
Author
There was a problem hiding this comment.
Unskipped and fixed the test. The fix includes:
- Recursive null complex type tracking (IdentifyNullComplexTypes)
- Property chain navigation for getting values from nested complex types
- Only setting complex properties declared directly on the current structural type to avoid navigation issues
All 4 tests pass including the complex collection test with double nested nullable complex properties. Commit a2c2438
…alue types and complex types Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
test/EFCore.Tests/ChangeTracking/Internal/PropertyValuesTest.cs
Outdated
Show resolved
Hide resolved
…rotected, simplify navigation logic, update tests WIP: Complex collection test with 3-level nesting fails - investigating issue with recursive ToObject calls Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
… for complex collection items Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #37516
Description
When calling
context.Entry(...).OriginalValues.ToObject(), anInvalidCastExceptionis thrown when entities have nested nullable complex properties and any of those nested properties are null.Customer impact
This prevents customers from using
OriginalValues.ToObject()with nested nullable complex properties.Workaround: Customers can set the AppContext switch
Microsoft.EntityFrameworkCore.Issue37516totrueto revert to the old behavior, but this disables the nullable complex property feature added in 10.0.2.How found
Customer reported on 10.0.2.
Regression
Yes, this is a regression from 10.0.1, introduced in #37302
Testing
Tests added.
Risk
Low. Quirk mode added.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.