|
| 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 | +--> |
0 commit comments