Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| [DriveInfo.DriveFormat returns Linux filesystem types](core-libraries/10.0/driveinfo-driveformat-linux.md) | Behavioral change | Preview 6 |
| [DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor](core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md) | Binary/source incompatible | Preview 7 |
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change | Preview 5 |
| [System.Drawing OutOfMemoryException changed to ExternalException](core-libraries/10.0/system-drawing-outofmemory-externalexception.md) | Behavioral change | Preview 5 |
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
| [.NET runtime no longer provides default SIGTERM signal handler](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: "Breaking change: System.Drawing OutOfMemoryException changed to ExternalException"
description: "Learn about the breaking change in .NET 10 where System.Drawing GDI+ OutOfMemory errors now throw ExternalException instead of OutOfMemoryException."
ms.date: 08/15/2025
ai-usage: ai-assisted
---

# System.Drawing OutOfMemoryException changed to ExternalException

GDI+ error handling in System.Drawing has been updated to throw <xref:System.Runtime.InteropServices.ExternalException> instead of <xref:System.OutOfMemoryException> for `Status.OutOfMemory` errors.

## Version introduced

.NET 10 Preview 5

## Previous behavior

When GDI+ encountered `Status.OutOfMemory` errors (often due to invalid input rather than actual memory issues), System.Drawing APIs threw <xref:System.OutOfMemoryException>.

## New behavior

When GDI+ encounters `Status.OutOfMemory` errors, System.Drawing APIs now throw <xref:System.Runtime.InteropServices.ExternalException> instead.

## Type of breaking change

This is a [behavioral change](../../categories.md#behavioral-change).

## Reason for change

GDI+ isn't particularly good at returning errors when it's unable to create internal objects. There are many cases where object creation fails due to invalid input, and higher-level code gets a null and turns it into `Status.OutOfMemory`. This is frequently a source of confusion since the error is often not related to actual memory issues.

The change to `ExternalException` provides more accurate error reporting, as this exception type is already thrown in other System.Drawing code paths for similar GDI+ errors.

## Recommended action

If your code catches `OutOfMemoryException` when using System.Drawing APIs, ensure you also catch `ExternalException` to handle these GDI+ errors.

```csharp
try
{
// System.Drawing operations
}
catch (ExternalException ex)
{
// Handle GDI+ errors (including former OutOfMemoryException cases)
}
catch (OutOfMemoryException ex)
{
// Handle actual memory issues
}
```

## Affected APIs

All System.Drawing APIs that interact with GDI+ and previously could throw `OutOfMemoryException` for `Status.OutOfMemory` errors, including but not limited to:

- <xref:System.Drawing.Bitmap?displayProperty=fullName> constructors and methods
- <xref:System.Drawing.Graphics?displayProperty=fullName> methods
- <xref:System.Drawing.Image?displayProperty=fullName> methods
- <xref:System.Drawing.Icon?displayProperty=fullName> constructors and methods
- Other System.Drawing types that use GDI+ internally
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ items:
href: core-libraries/10.0/sigterm-signal-handler.md
- name: System.Linq.AsyncEnumerable included in core libraries
href: core-libraries/10.0/asyncenumerable.md
- name: System.Drawing OutOfMemoryException changed to ExternalException
href: core-libraries/10.0/system-drawing-outofmemory-externalexception.md
- name: YMM embedded rounding removed from AVX10.2
href: core-libraries/10.0/ymm-embedded-rounding.md
- name: Cryptography
Expand Down
Loading