Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ If you're migrating an app to .NET 6.0, the breaking changes listed here might a

- [Selected TableLayoutSettings properties throw InvalidEnumArgumentException](windows-forms/6.0/tablelayoutsettings-apis-throw-invalidenumargumentexception.md)
- [NotifyIcon.Text maximum text length increased](windows-forms/6.0/notifyicon-text-max-text-length-increased.md)
- [Some APIs throw ArgumentNullException](windows-forms/6.0/apis-throw-argumentnullexception.md)
- [TreeNodeCollection.Item throws exception if node is assigned elsewhere](windows-forms/6.0/treenodecollection-item-throws-argumentexception.md)
4 changes: 4 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
href: aspnet-core/6.0/kestrel-log-message-attributes-changed.md
- name: Windows Forms
items:
- name: APIs throw ArgumentNullException
href: windows-forms/6.0/apis-throw-argumentnullexception.md
- name: NotifyIcon.Text maximum text length increased
href: windows-forms/6.0/notifyicon-text-max-text-length-increased.md
- name: TableLayoutSettings properties throw InvalidEnumArgumentException
Expand Down Expand Up @@ -574,6 +576,8 @@
items:
- name: .NET 6.0
items:
- name: APIs throw ArgumentNullException
href: windows-forms/6.0/apis-throw-argumentnullexception.md
- name: NotifyIcon.Text maximum text length increased
href: windows-forms/6.0/notifyicon-text-max-text-length-increased.md
- name: TableLayoutSettings properties throw InvalidEnumArgumentException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: "Breaking change: Some APIs throw ArgumentNullException"
description: Learn about the breaking change in .NET 6.0 where some APIs validate arguments and now throw an ArgumentNullException.
ms.date: 01/29/2021
---
# Some APIs throw ArgumentNullException

Some APIs now validate input parameters and throw an <xref:System.ArgumentNullException> where previously they threw a <xref:System.NullReferenceException>, if invoked with `null` input arguments.

## Change description

In previous .NET versions, the affected APIs throw a <xref:System.NullReferenceException> if invoked with an argument that's `null`.

Starting in .NET 6.0, the affected APIs throw an <xref:System.ArgumentNullException> if invoked with an argument that's `null`.

## Reason for change

Throwing <xref:System.ArgumentNullException> conforms to .NET Runtime behavior. It provides a better debug experience by clearly communicating which argument caused the exception.

## Version introduced

.NET 6.0

## Recommended action

- Review and, if necessary, update your code to prevent passing `null` input arguments to the affected APIs.
- If your code handles <xref:System.NullReferenceException>, replace or add an additional handler for <xref:System.ArgumentNullException>.

## Affected APIs

The following table lists the affected properties:

| Property | Version changed |
|-|-|-|-|
| <xref:System.Windows.Forms.TreeNodeCollection.Item(System.Int32)?displayProperty=fullName> | Preview 1 |

<!--

### Affected APIs

- `P:System.Windows.Forms.TreeNodeCollection.Item(System.Int32)`

### Category

Windows Forms

-->