Breaking change doc: Nullable.GetUnderlyingType throws for custom Type subclasses (.NET 11)#53409
Conversation
…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>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
|
@gewarren @jkotas These changes have been merged. I think it will be going into .NET 11 Preview 4 - dotnet/runtime#126905. |
There was a problem hiding this comment.
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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@gewarren I'm seeing
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). |
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
Closes #53407
In .NET 11 Preview 4,
Nullable.GetUnderlyingTypewas changed to delegate to the newType.GetNullableUnderlyingType()virtual. The base implementation throwsNotSupportedException, so customTypesubclasses that don't override it now throw where they previously returnednull.Changes
docs/core/compatibility/core-libraries/11/nullable-getunderlyingtype-throws.md— covers previous/new behavior, reason (fixesMetadataLoadContextnullable detection bug), and three override patterns:null(subclass never representsNullable<T>)Typedocs/core/compatibility/toc.yml— adds entry under .NET 11 / Core .NET librariesdocs/core/compatibility/11.md— adds row to the Core .NET libraries breaking changes tableAffected APIs
System.Nullable.GetUnderlyingType(System.Type)System.Type.GetNullableUnderlyingType(new virtual)Internal previews