Some APIs throw ArgumentNullException (.NET 7)
Some APIs now validate input parameters and throw an ArgumentNullException where previously they threw a NullReferenceException, if invoked with null
input arguments.
Previous behavior
In previous .NET versions, the affected APIs throw a NullReferenceException if invoked with an argument that's null
.
New behavior
Starting in .NET 7, 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 7
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 | Change version |
---|---|---|
ComboBox.ChildAccessibleObject(ComboBox, IntPtr) | owner |
Preview 1 |
ControlPaint.CreateHBitmap16Bit(Bitmap, Color) | bitmap |
Preview 1 |
ControlPaint.CreateHBitmapColorMask(Bitmap, IntPtr) | bitmap |
Preview 1 |
DataGridViewEditingControlShowingEventArgs(Control, DataGridViewCellStyle) | control or cellStyle |
Preview 1 |
ToolStripArrowRenderEventArgs(Graphics, ToolStripItem, Rectangle, Color, ArrowDirection) | g |
Preview 1 |
ToolStripContentPanelRenderEventArgs(Graphics, ToolStripContentPanel) | g or contentPanel |
Preview 1 |
ToolStripItemRenderEventArgs(Graphics, ToolStripItem) | g or item |
Preview 1 |
ToolStripPanelRenderEventArgs(Graphics, ToolStripPanel) | g or toolStripPanel |
Preview 1 |
ListView.CheckedIndexCollection(ListView) | owner |
Preview 5 |