Skip to content

[release/11.0] Preserve null results from primitive collection element converters - #39288

Merged
AndriySvyryd merged 5 commits into
release/11.0from
copilot/fix-nullreferenceexception-primitive-collection
Oct 20, 2026
Merged

AndriySvyryd merged 5 commits into
release/11.0from
copilot/fix-nullreferenceexception-primitive-collection

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #39245

Description
Preserve null results returned by element converters for non-null values when reading nullable struct primitive collections.

Customer impact
Queries throw NullReferenceException when a non-null JSON element converts to null, preventing affected collections from materializing. No known workaround for 11.0.0 that preserves the intended semantics. 

How found
Customer-reported on 11.0 RC1.

Regression
No. The related write failure was fixed for 11.0 RC1 in #37984, but the fix missed the reading part.

Testing
Tests added

Risk
Low, the production change is localized to nullable struct collection reads using the cast wrapper.

Copilot AI changed the title [WIP] Fix NullReferenceException for primitive collection value converter Preserve null results from primitive collection element converters Oct 16, 2026
Copilot AI requested a review from AndriySvyryd October 16, 2026 20:27
@AndriySvyryd AndriySvyryd changed the title Preserve null results from primitive collection element converters [release/11.0] Preserve null results from primitive collection element converters Oct 16, 2026

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.

🟡 Changes recommended

Both new theories need Cosmos-specific overrides because that provider rejects element converters during model validation.

1 open issue
What changed in this PR

Fixes nullable primitive-collection JSON reads when an element converter returns null, addressing #39245.

Changes:

  • Bypasses the non-nullable cast wrapper when reading converted elements.
  • Adds regression coverage for nullable integers and structs, writes, collection reuse, and reader reconstruction.
File Description
test/​EFCore.Specification.Tests/​JsonTypesTestBase.cs Adds null-returning converter regression tests.
src/​EFCore/​Storage/​Json/​JsonCollectionOfNullableStructsReaderWriter.cs Preserves converter-produced null elements during reads.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

release/11.0 2e88827 copilot/fix-nullrefe... 135549a +/-
76% 67% -9%
View coverage of the 10 most impacted files.
File release/11.0 2e88827 copilot/fix-nullrefe... 135549a +/-
/Users/runner/w...nal/Snapshot.cs 0% 60% +60%
D:\a\efcore\efc...nal\Snapshot.cs 0% 64% +64%
/home/runner/wo...nal/Snapshot.cs 0% 66% +66%
/home/runner/wo...yTypeBuilder.cs 0% 88% +88%
D:\a\efcore\efc...yTypeBuilder.cs 0% 88% +88%
/Users/runner/w...ngs.Designer.cs 0% 92% +92%
/home/runner/wo...ctExpression.cs 0% 93% +93%
D:\a\efcore\efc...ctExpression.cs 0% 93% +93%
D:\a\efcore\efc...ngs.Designer.cs 0% 94% +94%
/home/runner/wo...ngs.Designer.cs 0% 95% +95%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 17, 2026 00:21 UTC

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 16, 2026 23:50
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 16, 2026 23:50
Copilot AI balanced review requested due to automatic review settings October 16, 2026 23:50

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.

🟢 Approval recommended

The localized fix addresses the reported failure with focused regression coverage and no unresolved findings.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

new in 11 and customer reported. Approved.

@AndriySvyryd
AndriySvyryd merged commit 76a4f43 into release/11.0 Oct 20, 2026
23 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-nullreferenceexception-primitive-collection branch October 20, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

5 participants