Skip to content

Breaking change doc: Nullable.GetUnderlyingType throws for custom Type subclasses (.NET 11)#53409

Merged
AaronRobinsonMSFT merged 6 commits intomainfrom
copilot/fix-nullable-getunderlyingtype-issue
Apr 29, 2026
Merged

Breaking change doc: Nullable.GetUnderlyingType throws for custom Type subclasses (.NET 11)#53409
AaronRobinsonMSFT merged 6 commits intomainfrom
copilot/fix-nullable-getunderlyingtype-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

Closes #53407

In .NET 11 Preview 4, Nullable.GetUnderlyingType was changed to delegate to the new Type.GetNullableUnderlyingType() virtual. The base implementation throws NotSupportedException, so custom Type subclasses that don't override it now throw where they previously returned null.

Changes

  • New article docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md — covers previous/new behavior, reason (fixes MetadataLoadContext nullable detection bug), and three override patterns:
    • Return null (subclass never represents Nullable<T>)
    • Inspect generic type definition and return the type argument
    • Delegate to an inner wrapped Type
  • docs/core/compatibility/toc.yml — adds entry under .NET 11 / Core .NET libraries
  • docs/core/compatibility/11.md — adds row to the Core .NET libraries breaking changes table

Affected APIs

  • System.Nullable.GetUnderlyingType(System.Type)
  • System.Type.GetNullableUnderlyingType (new virtual)

Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/11.md Breaking changes in .NET 11
docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Nullable.GetUnderlyingType throws for custom Type subclasses
docs/core/compatibility/toc.yml docs/core/compatibility/toc

…stom Type subclasses

Agent-Logs-Url: https://github.com/dotnet/docs/sessions/2c45f021-3ef8-4caf-855a-7ea80054cb39

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Nullable.GetUnderlyingType to handle custom Type subclasses Breaking change doc: Nullable.GetUnderlyingType throws for custom Type subclasses (.NET 11) Apr 28, 2026
Copilot AI requested a review from gewarren April 28, 2026 21:29
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

@gewarren @jkotas These changes have been merged. I think it will be going into .NET 11 Preview 4 - dotnet/runtime#126905.

@gewarren gewarren marked this pull request as ready for review April 29, 2026 16:26
@gewarren gewarren requested a review from a team as a code owner April 29, 2026 16:26
Copilot AI review requested due to automatic review settings April 29, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new .NET 11 breaking change article documenting that Nullable.GetUnderlyingType(Type) now forwards to Type.GetNullableUnderlyingType() and can throw NotSupportedException for custom Type subclasses that don’t override the new virtual.

Changes:

  • Adds a new breaking change article describing the behavior change, rationale, and recommended override patterns.
  • Updates the .NET compatibility TOC to include the new article under .NET 11 core libraries.
  • Updates the .NET 11 breaking changes index table to reference the new article.

Reviewed changes

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

File Description
docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md New breaking change article documenting the new forwarding behavior and mitigation guidance.
docs/core/compatibility/toc.yml Adds the new breaking change article to the navigation tree.
docs/core/compatibility/11.md Adds the new breaking change entry to the .NET 11 index table.

Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

@gewarren
Copy link
Copy Markdown
Contributor

@gewarren I'm seeing

Cross reference not found: 'System.Type.GetNullableUnderlyingType'.

in https://buildapi.docs.microsoft.com/Output/PullRequest/a3bda507-3390-de91-8f7f-26f90f4e5fc8/202604291851254639-53409/BuildReport?accessString=aa4585a1989a22ee47264fec513db0a7ccd24ebb715277e92091f33bdc1d25d9. Is this a real error?

@AaronRobinsonMSFT Yes, it's a real error because that method isn't published in the .NET API reference. I assume this is a new API for Preview 4? We can either wait to merge this until the Preview 4 APIs are published, or we can just put the API name in backticks for now (instead of an xref).

Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Comment thread docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md Outdated
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 081c4ba into main Apr 29, 2026
11 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the copilot/fix-nullable-getunderlyingtype-issue branch April 29, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Breaking change]: Nullable.GetUnderlyingType throws on custom Type subclasses that don't override Type.GetNullableUnderlyingType

5 participants