Some APIs throw ArgumentNullException
Some APIs now validate input parameters and throw an ArgumentNullException where previously they threw a NullReferenceException, if invoked with null
input arguments.
Change description
In previous .NET versions, the affected APIs throw a NullReferenceException if invoked with an argument that's null
.
Starting in .NET 6, the affected APIs throw an ArgumentNullException if invoked with an argument that's null
.
Change category
This change affects binary compatibility.
Reason for change
Throwing ArgumentNullException conforms to .NET Runtime behavior. It provides a better debug experience by clearly communicating which argument caused the exception.
Version introduced
.NET 6
Recommended action
- Review and, if necessary, update your code to prevent passing
null
input arguments to the affected APIs. - If your code handles NullReferenceException, replace or add an additional handler for ArgumentNullException.
Affected APIs
The following table lists the affected APIs and specific parameters:
Method/property | Parameter name |
---|---|
System.Windows.Forms.TreeNodeCollection.Item[Int32] | index |
DrawTreeNodeEventArgs(Graphics, TreeNode, Rectangle, TreeNodeStates) | graphics |
DataGridViewRowStateChangedEventArgs(DataGridViewRow, DataGridViewElementStates) | dataGridViewRow |
DataGridViewColumnStateChangedEventArgs(DataGridViewColumn, DataGridViewElementStates) | dataGridViewColumn |