Changes to nullable reference type annotations
In .NET 6, some nullability annotations in the .NET libraries have changed.
Change description
In previous .NET versions, some nullable reference type annotations are incorrect, and build warnings are either absent or incorrect. Starting in .NET 6, 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.
Some of these changes are considered to be breaking because they can lead to new build-time warnings. When you migrate to .NET 6, code that references these APIs will need to be updated.
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 necessary.
Version introduced
6.0
Type of breaking change
This change can affect source compatibility.
Reason for change
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.
Recommended action
Update code that calls these APIs to reflect the revised nullability contracts.
Affected APIs
The following table lists the affected APIs:
API | What changed | Breaking or nonbreaking |
---|---|---|
ISite.Container | Property type is nullable | Breaking |
XContainer.Add(Object[]) | Parameter type is nullable | Nonbreaking |
XContainer.AddFirst(Object[]) | Parameter type is nullable | Nonbreaking |
XContainer.ReplaceNodes(Object[]) | Parameter type is nullable | Nonbreaking |
XDocument(Object[]) | Parameter type is nullable | Nonbreaking |
XDocument(XDeclaration, Object[]) | Parameter type is nullable | Nonbreaking |
XElement(XName, Object[]) | Second parameter type is nullable | Nonbreaking |
XElement.ReplaceAll(Object[]) | Parameter type is nullable | Nonbreaking |
XElement.ReplaceAttributes(Object[]) | Parameter type is nullable | Nonbreaking |
XNode.AddAfterSelf(Object[]) | Parameter type is nullable | Nonbreaking |
XNode.AddBeforeSelf(Object[]) | Parameter type is nullable | Nonbreaking |
XNode.ReplaceWith(Object[]) | Parameter type is nullable | Nonbreaking |
XStreamingElement(XName, Object) | Second parameter type is nullable | Nonbreaking |
XStreamingElement(XName, Object[]) | Second parameter type is nullable | Nonbreaking |
XStreamingElement.Add(Object[]) | Parameter type is nullable | Nonbreaking |
HttpClient.PatchAsync | content parameter type is nullable |
Nonbreaking |
HttpClient.PostAsync | content parameter type is nullable |
Nonbreaking |
HttpClient.PutAsync | content parameter type is nullable |
Nonbreaking |
MethodCallExpression.Update(Expression, IEnumerable<Expression>) | First parameter type is nullable | Nonbreaking |
Expression<TDelegate>.Update(Expression, IEnumerable<ParameterExpression>) | Return type is not nullable | Nonbreaking |
IDataRecord.GetBytes(Int32, Int64, Byte[], Int32, Int32) | buffer parameter type is nullable |
Breaking |
IDataRecord.GetChars(Int32, Int64, Char[], Int32, Int32) | buffer parameter type is nullable |
Breaking |
DbDataRecord.GetBytes(Int32, Int64, Byte[], Int32, Int32) | buffer parameter type is nullable |
Breaking |
DbDataRecord.GetChars(Int32, Int64, Char[], Int32, Int32) | buffer parameter type is nullable |
Breaking |
System.Net.HttpListenerContext.AcceptWebSocketAsync | subProtocol parameter type is nullable |
Nonbreaking |
Methods that override Object.Equals(Object) and many others that return bool |
[NotNullWhen(true)] added to first nullable parameter |
Breaking |
ImmutableArray<T>.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
BitVector32.Equals(Object) | NotNullWhen(true) was added to the o parameter |
Breaking |
BitVector32.Section.Equals(Object) | NotNullWhen(true) was added to the o parameter |
Breaking |
BlobContentId.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
BlobHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
CustomDebugInformationHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
DocumentNameBlobHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
EntityHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
GuidHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
Handle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
ImportScopeHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
LocalConstantHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
NamespaceDefinitionHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
SequencePoint.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
SignatureHeader.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
EditAndContinueLogEntry.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
LabelHandle.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
Label.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
OpCode.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
DateOnly.Equals(System.Object) |
NotNullWhen(true) was added to the value parameter |
Breaking |
TimeOnly.Equals(System.Object) |
NotNullWhen(true) was added to the value parameter |
Breaking |
Pointer.Equals(Object) | NotNullWhen(true) was added to the obj parameter |
Breaking |
See also
Feedback
Submit and view feedback for