Skip to content

Commit bbdd2a8

Browse files
Copilotadegeo
andcommitted
Add System.Drawing OutOfMemoryException breaking change documentation for .NET 10
Co-authored-by: adegeo <[email protected]>
1 parent 970d5ed commit bbdd2a8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4444
| [DriveInfo.DriveFormat returns Linux filesystem types](core-libraries/10.0/driveinfo-driveformat-linux.md) | Behavioral change | Preview 6 |
4545
| [DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor](core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md) | Binary/source incompatible | Preview 7 |
4646
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change | Preview 5 |
47+
| [System.Drawing OutOfMemoryException changed to ExternalException](core-libraries/10.0/system-drawing-outofmemory-externalexception.md) | Behavioral change | Preview 5 |
4748
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
4849
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
4950
| [.NET runtime no longer provides default SIGTERM signal handler](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "Breaking change: System.Drawing OutOfMemoryException changed to ExternalException"
3+
description: "Learn about the breaking change in .NET 10 where System.Drawing GDI+ OutOfMemory errors now throw ExternalException instead of OutOfMemoryException."
4+
ms.date: 08/15/2025
5+
ai-usage: ai-assisted
6+
---
7+
8+
# System.Drawing OutOfMemoryException changed to ExternalException
9+
10+
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.
11+
12+
## Version introduced
13+
14+
.NET 10 Preview 5
15+
16+
## Previous behavior
17+
18+
When GDI+ encountered `Status.OutOfMemory` errors (often due to invalid input rather than actual memory issues), System.Drawing APIs threw <xref:System.OutOfMemoryException>.
19+
20+
## New behavior
21+
22+
When GDI+ encounters `Status.OutOfMemory` errors, System.Drawing APIs now throw <xref:System.Runtime.InteropServices.ExternalException> instead.
23+
24+
## Type of breaking change
25+
26+
This is a [behavioral change](../../categories.md#behavioral-change).
27+
28+
## Reason for change
29+
30+
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.
31+
32+
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.
33+
34+
## Recommended action
35+
36+
If your code catches `OutOfMemoryException` when using System.Drawing APIs, ensure you also catch `ExternalException` to handle these GDI+ errors.
37+
38+
```csharp
39+
try
40+
{
41+
// System.Drawing operations
42+
}
43+
catch (ExternalException ex)
44+
{
45+
// Handle GDI+ errors (including former OutOfMemoryException cases)
46+
}
47+
catch (OutOfMemoryException ex)
48+
{
49+
// Handle actual memory issues
50+
}
51+
```
52+
53+
## Affected APIs
54+
55+
All System.Drawing APIs that interact with GDI+ and previously could throw `OutOfMemoryException` for `Status.OutOfMemory` errors, including but not limited to:
56+
57+
- <xref:System.Drawing.Bitmap?displayProperty=fullName> constructors and methods
58+
- <xref:System.Drawing.Graphics?displayProperty=fullName> methods
59+
- <xref:System.Drawing.Image?displayProperty=fullName> methods
60+
- <xref:System.Drawing.Icon?displayProperty=fullName> constructors and methods
61+
- Other System.Drawing types that use GDI+ internally

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ items:
5454
href: core-libraries/10.0/sigterm-signal-handler.md
5555
- name: System.Linq.AsyncEnumerable included in core libraries
5656
href: core-libraries/10.0/asyncenumerable.md
57+
- name: System.Drawing OutOfMemoryException changed to ExternalException
58+
href: core-libraries/10.0/system-drawing-outofmemory-externalexception.md
5759
- name: YMM embedded rounding removed from AVX10.2
5860
href: core-libraries/10.0/ymm-embedded-rounding.md
5961
- name: Cryptography

0 commit comments

Comments
 (0)