Skip to content

Commit a10546c

Browse files
authored
Nullability annotations breaking change (#22798)
1 parent 3043ea9 commit a10546c

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

docs/core/compatibility/6.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ If you're migrating an app to .NET 6.0, the breaking changes listed here might a
1717
- [Middleware: HTTPS Redirection Middleware throws exception on ambiguous HTTPS ports](aspnet-core/6.0/middleware-ambiguous-https-ports-exception.md)
1818
- [Razor: RazorEngine APIs marked obsolete](aspnet-core/6.0/razor-engine-apis-obsolete.md)
1919

20+
## Core .NET libraries
21+
22+
- [Changes to nullable reference type annotations](core-libraries/6.0/nullable-ref-type-annotation-changes.md)
23+
2024
## Windows Forms
2125

2226
- [Selected TableLayoutSettings properties throw InvalidEnumArgumentException](windows-forms/6.0/tablelayoutsettings-apis-throw-invalidenumargumentexception.md)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "Breaking change: Nullable reference type annotation changes"
3+
description: Learn about the .NET 6.0 breaking change in core .NET libraries where some nullable reference type annotations have changed.
4+
ms.date: 02/11/2021
5+
---
6+
# Changes to nullable reference type annotations
7+
8+
In .NET 6.0, some nullability annotations in the .NET libraries have changed.
9+
10+
## Change description
11+
12+
In previous .NET versions, some nullable reference type annotations are incorrect, and build warnings are either absent or incorrect. Starting in .NET 6.0, some annotations that were previously applied have been updated. New build warnings will be produced and incorrect build warnings will no longer be produced for the affected APIs.
13+
14+
Some of these changes are considered to be *breaking* because they can lead to new build-time warnings. When you migrate to .NET 6.0, code that references these APIs will need to be updated.
15+
16+
Other changes that aren't considered to be breaking are also documented on this page. Any code that references the updated APIs may benefit from removing operators or pragmas that are no longer unnecessary.
17+
18+
## Version introduced
19+
20+
6.0
21+
22+
## Reason for change
23+
24+
Starting in .NET Core 3.0, nullability annotations were applied to the .NET libraries. From the outset of the effort, mistakes in these annotations were anticipated. Through feedback and further testing, the nullable annotations for the affected APIs were determined to be inaccurate. The updated annotations correctly represent the nullability contracts for the APIs.
25+
26+
## Recommended action
27+
28+
Update code that calls these APIs to reflect the revised nullability contracts.
29+
30+
## Affected APIs
31+
32+
The following table lists the affected APIs:
33+
34+
| API | What changed | Breaking or nonbreaking | Version added |
35+
| - | - | - |
36+
| <xref:System.ComponentModel.ISite.Container?displayProperty=nameWithType> | Property type is nullable | Breaking | Preview 1 |
37+
| <xref:System.Xml.Linq.XContainer.Add(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
38+
| <xref:System.Xml.Linq.XContainer.AddFirst(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
39+
| <xref:System.Xml.Linq.XContainer.ReplaceNodes(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
40+
| <xref:System.Xml.Linq.XDocument.%23ctor(System.Object[])> | Parameter type is nullable | Nonbreaking | Preview 1 |
41+
| <xref:System.Xml.Linq.XDocument.%23ctor(System.Xml.Linq.XDeclaration,System.Object[])> | Parameter type is nullable | Nonbreaking | Preview 1 |
42+
| <xref:System.Xml.Linq.XElement.%23ctor(System.Xml.Linq.XName,System.Object[])> | Second parameter type is nullable | Nonbreaking | Preview 1 |
43+
| <xref:System.Xml.Linq.XElement.ReplaceAll(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
44+
| <xref:System.Xml.Linq.XElement.ReplaceAttributes(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
45+
| <xref:System.Xml.Linq.XNode.AddAfterSelf(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
46+
| <xref:System.Xml.Linq.XNode.AddBeforeSelf(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
47+
| <xref:System.Xml.Linq.XNode.ReplaceWith(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
48+
| <xref:System.Xml.Linq.XStreamingElement.%23ctor(System.Xml.Linq.XName,System.Object)> | Second parameter type is nullable | Nonbreaking | Preview 1 |
49+
| <xref:System.Xml.Linq.XStreamingElement.%23ctor(System.Xml.Linq.XName,System.Object[])> | Second parameter type is nullable | Nonbreaking | Preview 1 |
50+
| <xref:System.Xml.Linq.XStreamingElement.Add(System.Object[])?displayProperty=nameWithType> | Parameter type is nullable | Nonbreaking | Preview 1 |
51+
| <xref:System.Net.Http.HttpClient.PatchAsync%2A?displayProperty=nameWithType> | `content` parameter type is nullable | Nonbreaking | Preview 1 |
52+
| <xref:System.Net.Http.HttpClient.PostAsync%2A?displayProperty=nameWithType> | `content` parameter type is nullable | Nonbreaking | Preview 1 |
53+
| <xref:System.Net.Http.HttpClient.PutAsync%2A?displayProperty=nameWithType> | `content` parameter type is nullable | Nonbreaking | Preview 1 |
54+
| <xref:System.Linq.Expressions.MethodCallExpression.Update(System.Linq.Expressions.Expression,System.Collections.Generic.IEnumerable{System.Linq.Expressions.Expression})?displayProperty=nameWithType> | First parameter type is nullable | Nonbreaking | Preview 1 |
55+
| <xref:System.Linq.Expressions.Expression%601.Update(System.Linq.Expressions.Expression,System.Collections.Generic.IEnumerable{System.Linq.Expressions.ParameterExpression})?displayProperty=nameWithType> | Return type is not nullable | Nonbreaking | Preview 1 |
56+
| <xref:System.Data.IDataRecord.GetBytes(System.Int32,System.Int64,System.Byte[],System.Int32,System.Int32)?displayProperty=nameWithType> | `buffer` parameter type is nullable | Breaking | Preview 1 |
57+
| <xref:System.Data.IDataRecord.GetChars(System.Int32,System.Int64,System.Char[],System.Int32,System.Int32)?displayProperty=nameWithType> | `buffer` parameter type is nullable | Breaking | Preview 1 |
58+
| <xref:System.Data.Common.DbDataRecord.GetBytes(System.Int32,System.Int64,System.Byte[],System.Int32,System.Int32)?displayProperty=nameWithType> | `buffer` parameter type is nullable | Breaking | Preview 1 |
59+
| <xref:System.Data.Common.DbDataRecord.GetChars(System.Int32,System.Int64,System.Char[],System.Int32,System.Int32)?displayProperty=nameWithType> | `buffer` parameter type is nullable | Breaking | Preview 1 |
60+
61+
<!--
62+
63+
### Category
64+
65+
Core .NET libraries
66+
67+
### Affected APIs
68+
69+
- `P:System.ComponentModel.ISite.Container`
70+
- `M:System.Xml.Linq.XContainer.Add(System.Object[])`
71+
- `M:System.Xml.Linq.XContainer.AddFirst(System.Object[])`
72+
- `M:System.Xml.Linq.XContainer.ReplaceNodes(System.Object[])`
73+
- `M:System.Xml.Linq.XDocument.#ctor(System.Object[])`
74+
- `M:System.Xml.Linq.XDocument.#ctor(System.Xml.Linq.XDeclaration,System.Object[])`
75+
- `M:System.Xml.Linq.XElement.#ctor(System.Xml.Linq.XName,System.Object[])`
76+
- `M:System.Xml.Linq.XElement.ReplaceAll(System.Object[])`
77+
- `M:System.Xml.Linq.XElement.ReplaceAttributes(System.Object[])`
78+
- `M:System.Xml.Linq.XNode.AddAfterSelf(System.Object[])`
79+
- `M:System.Xml.Linq.XNode.AddBeforeSelf(System.Object[])`
80+
- `M:System.Xml.Linq.XNode.ReplaceWith(System.Object[])`
81+
- `M:System.Xml.Linq.XStreamingElement.#ctor(System.Xml.Linq.XName,System.Object)`
82+
- `M:System.Xml.Linq.XStreamingElement.#ctor(System.Xml.Linq.XName,System.Object[])`
83+
- `M:System.Xml.Linq.XStreamingElement.Add(System.Object[])`
84+
- `O:System.Net.Http.HttpClient.PatchAsync`
85+
- `O:System.Net.Http.HttpClient.PostAsync`
86+
- `O:System.Net.Http.HttpClient.PutAsync`
87+
- `M:System.Linq.Expressions.MethodCallExpression.Update(System.Linq.Expressions.Expression,System.Collections.Generic.IEnumerable{System.Linq.Expressions.Expression})`
88+
- `M:System.Linq.Expressions.Expression%601.Update(System.Linq.Expressions.Expression,System.Collections.Generic.IEnumerable{System.Linq.Expressions.ParameterExpression})`
89+
- `M:System.Data.IDataRecord.GetBytes(System.Int32,System.Int64,System.Byte[],System.Int32,System.Int32)`
90+
- `M:System.Data.IDataRecord.GetChars(System.Int32,System.Int64,System.Char[],System.Int32,System.Int32)`
91+
- `M:System.Data.Common.DbDataRecord.GetBytes(System.Int32,System.Int64,System.Byte[],System.Int32,System.Int32)`
92+
- `M:System.Data.Common.DbDataRecord.GetChars(System.Int32,System.Int64,System.Char[],System.Int32,System.Int32)`
93+
94+
-->

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
href: aspnet-core/6.0/middleware-ambiguous-https-ports-exception.md
3333
- name: "Razor: RazorEngine APIs marked obsolete"
3434
href: aspnet-core/6.0/razor-engine-apis-obsolete.md
35+
- name: Core .NET libraries
36+
items:
37+
- name: Nullability annotation changes
38+
href: core-libraries/6.0/nullable-ref-type-annotation-changes.md
3539
- name: Windows Forms
3640
items:
3741
- name: APIs throw ArgumentNullException
@@ -418,6 +422,10 @@
418422
href: code-analysis/5.0/ca2247-ctor-arg-should-be-taskcreationoptions.md
419423
- name: Core .NET libraries
420424
items:
425+
- name: .NET 6.0
426+
items:
427+
- name: Nullability annotation changes
428+
href: core-libraries/6.0/nullable-ref-type-annotation-changes.md
421429
- name: .NET 5.0
422430
items:
423431
- name: Assembly-related API changes for single-file publishing

0 commit comments

Comments
 (0)