Skip to content

Commit b2cf4c6

Browse files
CamSoperadegeo
andauthored
[Breaking change]: Crashes due to incorrect usage of DyanmicResource's (#46093)
* [Breaking change]: Crashes due to incorrect usage of `DyanmicResource`'s Fixes #46089 * Remove quote that snuck in --------- Co-authored-by: Andy (Steve) De George <[email protected]>
1 parent 99ebc45 commit b2cf4c6

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,9 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
8181
| [Renamed parameter in HtmlElement.InsertAdjacentElement](windows-forms/10.0/insertadjacentelement-orientation.md) | Source incompatible | Preview 1 |
8282
| [TreeView checkbox image truncation](windows-forms/10.0/treeview-text-location.md) | Behavioral change | Preview 1 |
8383
| [StatusStrip uses System RenderMode by default](windows-forms/10.0/statusstrip-renderer.md) | Behavioral change | Preview 1 |
84+
85+
## Windows Presentation Foundation (WPF)
86+
87+
| Title | Type of change | Introduced version |
88+
|--------------------------------------------------------------------------------------------------|---------------------------------------|--------------------|
89+
| [Incorrect usage of DynamicResource causes application crash](wpf/10.0/dynamicresource-crash.md) | Source incompatible/behavioral change | Preview 4 |

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ items:
7878
href: windows-forms/10.0/treeview-text-location.md
7979
- name: StatusStrip uses System RenderMode by default
8080
href: windows-forms/10.0/statusstrip-renderer.md
81+
- name: WPF
82+
items:
83+
- name: Incorrect usage of DynamicResource causes application crash
84+
href: wpf/10.0/dynamicresource-crash.md
8185
- name: .NET 9
8286
items:
8387
- name: Overview
@@ -2290,6 +2294,10 @@ items:
22902294
href: winforms.md
22912295
- name: WPF
22922296
items:
2297+
- name: .NET 10
2298+
items:
2299+
- name: Incorrect usage of DynamicResource causes application crash
2300+
href: wpf/10.0/dynamicresource-crash.md
22932301
- name: .NET 9
22942302
items:
22952303
- name: "'GetXmlNamespaceMaps' type change"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "Breaking change - Incorrect usage of DynamicResource causes application crash"
3+
description: "Learn about the breaking change in .NET 10 Preview 4 where incorrect usage of DynamicResource now causes application crashes."
4+
ms.date: 5/12/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/dotnet/docs/issues/46089
7+
---
8+
9+
# Incorrect usage of DynamicResource causes application crash
10+
11+
Beginning with .NET 10 Preview 4, applications using `DynamicResource` incorrectly now crash at runtime.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 4
16+
17+
## Previous behavior
18+
19+
Applications that incorrectly initialized `DynamicResource` would continue running without crashing. The values would fall back to defaults, and an `InvalidOperationException` would appear in the output.
20+
21+
## New behavior
22+
23+
Applications now crash with an error similar to the following:
24+
25+
```output
26+
System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
27+
```
28+
29+
This occurs when an incorrect resource type is used with `DynamicResource`. For example, the code snippet below causes a crash because a `SolidColorBrush` is used instead of `System.Windows.Media.Color`:
30+
31+
```xml
32+
<SolidColorBrush x:Key="RedColorBrush" Color="#FFFF0000" />
33+
<SolidColorBrush x:Key="ResourceName" Color="{DynamicResource RedColorBrush}" />
34+
```
35+
36+
## Type of breaking change
37+
38+
This is both a [source-incompatible](../../categories.md#source-compatibility) and [behavioral](../../categories.md#behavioral-change) change.
39+
40+
## Reason for change
41+
42+
This change improves the performance of `DynamicResource` usage. The optimization ensures that incorrect resource initialization is caught immediately, preventing unintended behavior.
43+
44+
## Recommended action
45+
46+
To avoid crashes, ensure that the correct resource types are used with `DynamicResource`. For example, the following code resolves the issue by using `System.Windows.Media.Color` instead of `SolidColorBrush`:
47+
48+
```xml
49+
<Color x:Key="RedColor">#FFFF0000</Color>
50+
<SolidColorBrush x:Key="ResourceName" Color="{DynamicResource RedColor}" />
51+
```
52+
53+
## Affected APIs
54+
55+
None.

0 commit comments

Comments
 (0)