Skip to content

Commit 6954c15

Browse files
Copilotadegeogewarren
authored
Document System.Drawing OutOfMemoryException to ExternalException breaking change for .NET 10 with C# and VB examples (#47939)
* Initial plan * Add System.Drawing OutOfMemoryException breaking change documentation for .NET 10 Co-authored-by: adegeo <[email protected]> * Move System.Drawing breaking change from core-libraries to windows-forms Co-authored-by: adegeo <[email protected]> * Add VB.NET example and language metadata for System.Drawing breaking change Co-authored-by: adegeo <[email protected]> * Remove tab structure from code examples, let metadata handle rendering Co-authored-by: adegeo <[email protected]> * Update docs/core/compatibility/windows-forms/10.0/system-drawing-outofmemory-externalexception.md Co-authored-by: Genevieve Warren <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: adegeo <[email protected]> Co-authored-by: Genevieve Warren <[email protected]>
1 parent 65a3dac commit 6954c15

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
126126
| [Renamed parameter in HtmlElement.InsertAdjacentElement](windows-forms/10.0/insertadjacentelement-orientation.md) | Source incompatible | Preview 1 |
127127
| [TreeView checkbox image truncation](windows-forms/10.0/treeview-text-location.md) | Behavioral change | Preview 1 |
128128
| [StatusStrip uses System RenderMode by default](windows-forms/10.0/statusstrip-renderer.md) | Behavioral change | Preview 1 |
129+
| [System.Drawing OutOfMemoryException changed to ExternalException](windows-forms/10.0/system-drawing-outofmemory-externalexception.md) | Behavioral change | Preview 5 |
129130

130131
## Windows Presentation Foundation (WPF)
131132

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ items:
146146
href: windows-forms/10.0/treeview-text-location.md
147147
- name: StatusStrip uses System RenderMode by default
148148
href: windows-forms/10.0/statusstrip-renderer.md
149+
- name: System.Drawing OutOfMemoryException changed to ExternalException
150+
href: windows-forms/10.0/system-drawing-outofmemory-externalexception.md
149151
- name: WPF
150152
items:
151153
- name: Empty ColumnDefinitions and RowDefinitions are disallowed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
dev_langs:
7+
- CSharp
8+
- VB
9+
---
10+
11+
# System.Drawing OutOfMemoryException changed to ExternalException
12+
13+
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.
14+
15+
## Version introduced
16+
17+
.NET 10 Preview 5
18+
19+
## Previous behavior
20+
21+
When GDI+ encountered `Status.OutOfMemory` errors (often due to invalid input rather than actual memory issues), System.Drawing APIs threw <xref:System.OutOfMemoryException>.
22+
23+
## New behavior
24+
25+
Starting in .NET 10, when GDI+ encounters `Status.OutOfMemory` errors, System.Drawing APIs now throw <xref:System.Runtime.InteropServices.ExternalException>.
26+
27+
## Type of breaking change
28+
29+
This is a [behavioral change](../../categories.md#behavioral-change).
30+
31+
## Reason for change
32+
33+
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.
34+
35+
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.
36+
37+
## Recommended action
38+
39+
If your code catches `OutOfMemoryException` when using System.Drawing APIs, ensure you also catch `ExternalException` to handle these GDI+ errors.
40+
41+
```csharp
42+
try
43+
{
44+
// System.Drawing operations
45+
}
46+
catch (ExternalException ex)
47+
{
48+
// Handle GDI+ errors (including former OutOfMemoryException cases)
49+
}
50+
catch (OutOfMemoryException ex)
51+
{
52+
// Handle actual memory issues
53+
}
54+
```
55+
56+
```vb
57+
Try
58+
' System.Drawing operations
59+
Catch ex As ExternalException
60+
' Handle GDI+ errors (including former OutOfMemoryException cases)
61+
Catch ex As OutOfMemoryException
62+
' Handle actual memory issues
63+
End Try
64+
```
65+
66+
## Affected APIs
67+
68+
All System.Drawing APIs that interact with GDI+ and previously could throw `OutOfMemoryException` for `Status.OutOfMemory` errors, including but not limited to:
69+
70+
- <xref:System.Drawing.Bitmap?displayProperty=fullName> constructors and methods
71+
- <xref:System.Drawing.Graphics?displayProperty=fullName> methods
72+
- <xref:System.Drawing.Image?displayProperty=fullName> methods
73+
- <xref:System.Drawing.Icon?displayProperty=fullName> constructors and methods
74+
- Other System.Drawing types that use GDI+ internally

0 commit comments

Comments
 (0)