WinForms メソッドで ArgumentNullException がスローされるようになった

一部の Windows フォーム メソッドで、null 引数について ArgumentNullException がスローされるようになりました。以前は NullReferenceException がスローされていました。

変更の説明

以前は、null の引数が渡された場合、特定の Windows フォーム メソッドでは NullReferenceException がスローされていました。 .NET 5 以降、これらのメソッドでは、null 引数に対して ArgumentNullException が代わりにスローされるようになりました。

ArgumentNullException をスローすることは、.NET ランタイムの動作に準拠しています。 また、引数が null であることと、どの引数がそうであるのかが明確に伝えられることで、デバッグ エクスペリエンスが向上します。

導入されたバージョン

.NET 5.0

これらのメソッドのいずれかを呼び出す場合、コードでは現在 null 引数について NullReferenceException をキャッチする場合は、代わりに ArgumentNullException をキャッチします。 さらに、リストされているメソッドに null 引数が渡されないようにコードを更新することを検討してください。

影響を受ける API

次の表では、影響を受けるメソッドとパラメーターを示します。

メソッド パラメーター名 追加されたバージョン
Control.ControlCollection(Control) owner Preview 1
TabControl.GetToolTipText(Object) item Preview 1
TableLayoutControlCollection(TableLayoutPanel) container Preview 1
ToolStripRenderer.OnRenderArrow(ToolStripArrowRenderEventArgs) e Preview 1
ToolStripRenderer.OnRenderItemCheck(ToolStripItemImageRenderEventArgs) e Preview 1
ToolStripRenderer.OnRenderItemImage(ToolStripItemImageRenderEventArgs) e Preview 1
ToolStripRenderer.OnRenderItemText(ToolStripItemTextRenderEventArgs) e Preview 1
ToolStripRenderer.OnRenderStatusStripSizingGrip(ToolStripRenderEventArgs) > e Preview 1
DataGridViewComboBoxEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyle) dataGridViewCellStyle Preview 2
RichTextBox.LoadFile(Stream, RichTextBoxStreamType) data Preview 2
ListBox.IntegerCollection(ListBox) owner Preview 5
ListBox.IntegerCollection.CopyTo(Array, Int32) destination Preview 5
ListViewGroup.ISerializable.GetObjectData(SerializationInfo, StreamingContext) info Preview 5
VisualStyleRenderer(String, Int32, Int32) className Preview 5
ListBox.ObjectCollection(ListBox) owner Preview 6
ListBox.ObjectCollection(ListBox, Object[]) ownervalue Preview 6
ListBox.ObjectCollection(ListBox, ListBox+ObjectCollection) ownervalue Preview 6
ListBox.ObjectCollection.AddRange(Object[]) items Preview 6
ListBox.ObjectCollection.AddRange(ListBox+ObjectCollection) value Preview 6
ListBox.ObjectCollection.CopyTo(Object[], Int32) destination Preview 6
ListBox.ObjectCollection.ICollection.CopyTo(Array, Int32) destination Preview 6
ListView.SelectedIndexCollection(ListView) owner Preview 7
TreeNodeCollection.Find(String, Boolean) keynull または空です Preview 8
ListView.ListViewItemCollection.Find(String, Boolean) keynull または空です RC1
ScrollableControl.OnPaintBackground(PaintEventArgs) e RC1