Description
Changes to Nullable Reference Type Annotations in .NET 6.0
This issue represents a work-in-progress. All changes to nullability annotations in the .NET Libraries will be aggregated into this issue throughout the course of .NET 6.0.
Starting in .NET Core 3.0, we have been applying nullability annotations to the .NET Libraries; .NET 5.0 reached 94% coverage across the APIs. From the outset of this effort, we anticipated that mistakes would be made in these annotations and fixes would need to be made. In .NET 6.0, we are updating some annotations that have been previously applied.
Some of these changes are considered breaking changes because they could lead to new build-time warnings--code referencing these APIs will need to be updated when migrating to .NET 6.0. Other changes that are not considered breaking are also documented here as referencing code may benefit from removing operators or pragmas that become unnecessary.
Old behavior
The affected APIs had incorrect nullable reference type annotations and build warnings were either absent or incorrect.
New behavior
New build warnings will be produced and incorrect build warnings will no longer be produced for the affected APIs.
Reason for change
Through feedback and further testing, the nullable annotations for the affected APIs were determined to be inaccurate. The updated annotations now correctly represent the nullability contracts for the APIs.
Recommended action
Update code calling these APIs to reflect the revised nullability contracts.
Category
- Core .NET libraries
Affected APIs
(Unchecked items in the list have not yet been documented)
Version introduced: .NET 6.0 Preview 1
dotnet/runtime#42918 [Breaking]
dotnet/runtime#43717 [Non-Breaking]
- System.Xml.Linq.XContainer.Add(Object[])
- System.Xml.Linq.XContainer.AddFirst(Object[])
- System.Xml.Linq.XContainer.ReplaceNodes(Object[])
- System.Xml.Linq.XDocument(Object[])
- System.Xml.Linq.XDocument(XDeclaration, Object[])
- System.Xml.Linq.XElement(XName, Object[])
- System.Xml.Linq.XElement.ReplaceAll(Object[])
- System.Xml.Linq.XElement.ReplaceAttributes(Object[])
- System.Xml.Linq.XNode.AddAfterSelf(Object[])
- System.Xml.Linq.XNode.AddBeforeSelf(Object[])
- System.Xml.Linq.XNode.ReplaceWith(Object[])
- System.Xml.Linq.XStreamingElement(XName, Object)
- System.Xml.Linq.XStreamingElement(XName, Object[])
- System.Xml.Linq.XStreamingElement.Add(Object[])
dotnet/runtime#44880 [Non-Breaking]
- System.Net.Http.HttpClient.PatchAsync
- System.Net.Http.HttpClient.PostAsync
- System.Net.Http.HttpClient.PutAsync
dotnet/runtime#44844 [Non-Breaking]
- System.Linq.Expressions.MethodCallExpression.Update
- System.Linq.Expressions.Expression<TDelegate>.Update
dotnet/runtime#44938 [Breaking]
- System.Data.IDataRecord.GetBytes
- System.Data.IDataRecord.GetChars
- System.Data.DataRecord.GetBytes
- System.Data.DataRecord.GetChars
Version introduced: .NET 6.0 Preview 2
dotnet/runtime#47402 [Non-Breaking]
dotnet/runtime#47598 [Breaking]
-
[NotNullWhen(true)]
added to hundreds of arguments -
[NotNullWhen(true)]
added to a few arguments in System.collections missed in the original change -
[NotNullWhen(true)]
added to more arguments in System.Reflection missed in the original change -
[NotNullWhen(true)]
added to a few arguments in CoreLib missed in the original change
Issue metadata
- Issue type: breaking-change