Skip to content

Add consistent nullable unwrapping to dynamic resolvers#6548

Merged
NinoFloris merged 1 commit into
npgsql:mainfrom
NinoFloris:handle-nullable-dynamic
Apr 20, 2026
Merged

Add consistent nullable unwrapping to dynamic resolvers#6548
NinoFloris merged 1 commit into
npgsql:mainfrom
NinoFloris:handle-nullable-dynamic

Conversation

@NinoFloris

@NinoFloris NinoFloris commented Apr 20, 2026

Copy link
Copy Markdown
Member

Closes #6547

This should be backported until 8.x as well.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes #6547 by ensuring dynamic type resolvers handle Nullable<T> consistently (unwrap to T when generating mappings), preventing failures when array mappings are generated from value-type mappings.

Changes:

  • Unwrap Nullable<T> element types before calling AddArrayMapping(...) across several dynamic array resolvers (enum/tuple/json).
  • When auto-generating array mappings from an existing mapping set, skip Nullable<T> entries to avoid invalid Nullable<Nullable<T>> generic construction.
  • Extend similar nullable-unwrapping behavior to unmapped range/multirange array resolvers and align nullable checks/guards in DynamicTypeInfoResolver.

Reviewed changes

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

Show a summary per file
File Description
src/Npgsql/Internal/ResolverFactories/UnmappedTypeInfoResolverFactory.cs Unwraps nullable element types when generating range/multirange array mappings (including default-mapping fallback path).
src/Npgsql/Internal/ResolverFactories/TupledRecordTypeInfoResolverFactory.cs Adds nullable-aware matching for tuple record mappings and unwraps nullable element types for array mapping generation.
src/Npgsql/Internal/ResolverFactories/JsonDynamicTypeInfoResolverFactory.cs Unwraps nullable types when dynamically mapping json/jsonb and avoids generating array mappings for Nullable<T> base mappings.
src/Npgsql/Internal/DynamicTypeInfoResolver.cs Refactors mapping methods to consistently reject explicit nullable mappings for value types while keeping value/reference paths clearer.
src/Npgsql.Json.NET/Internal/JsonNetPocoTypeInfoResolverFactory.cs Mirrors the json/jsonb nullable-handling fixes for the Json.NET plugin resolver (skip nullable base mappings + unwrap element types).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql.Json.NET/Internal/JsonNetPocoTypeInfoResolverFactory.cs
@NinoFloris
NinoFloris merged commit 715baa7 into npgsql:main Apr 20, 2026
16 checks passed
@NinoFloris
NinoFloris deleted the handle-nullable-dynamic branch April 20, 2026 16:23
NinoFloris added a commit that referenced this pull request Apr 20, 2026
@NinoFloris

NinoFloris commented Apr 20, 2026

Copy link
Copy Markdown
Member Author

Backported to 10.0.3 via cb635a3, 9.0.6 via 44335cc, and 8.0.10 via 47f9c01.

NinoFloris added a commit that referenced this pull request Apr 20, 2026
@aradalvand

aradalvand commented Apr 21, 2026

Copy link
Copy Markdown

Hi @NinoFloris, thank you for the fix!
Has this been released yet? I don't see a new package version in NuGet.
Or should @roji publish a release manually?

@NinoFloris

Copy link
Copy Markdown
Member Author

They have just been backported for future release. We generally accumulate many other small fixes in these branches until we release new patch versions to nuget.

If you really need the fix today you can consider referencing our myget package (https://www.myget.org/feed/npgsql/package/nuget/Npgsql) for the most recent 10.0.3 branch instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Writing values of 'System.Guid[]' is not supported!

4 participants