Skip to content

[Breaking change]: Crashes due to incorrect usage of DyanmicResource's #46093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
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
6 changes: 6 additions & 0 deletions docs/core/compatibility/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| [Renamed parameter in HtmlElement.InsertAdjacentElement](windows-forms/10.0/insertadjacentelement-orientation.md) | Source incompatible | Preview 1 |
| [TreeView checkbox image truncation](windows-forms/10.0/treeview-text-location.md) | Behavioral change | Preview 1 |
| [StatusStrip uses System RenderMode by default](windows-forms/10.0/statusstrip-renderer.md) | Behavioral change | Preview 1 |

## Windows Presentation Foundation (WPF)

| Title | Type of change | Introduced version |
|--------------------------------------------------------------------------------------------------|---------------------------------------|--------------------|
| [Incorrect usage of DynamicResource causes application crash](wpf/10.0/dynamicresource-crash.md) | Source incompatible/behavioral change | Preview 4 |
8 changes: 8 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ items:
href: windows-forms/10.0/treeview-text-location.md
- name: StatusStrip uses System RenderMode by default
href: windows-forms/10.0/statusstrip-renderer.md
- name: WPF
items:
- name: Incorrect usage of DynamicResource causes application crash
href: wpf/10.0/dynamicresource-crash.md
- name: .NET 9
items:
- name: Overview
Expand Down Expand Up @@ -2278,6 +2282,10 @@ items:
href: winforms.md
- name: WPF
items:
- name: .NET 10
items:
- name: Incorrect usage of DynamicResource causes application crash
href: wpf/10.0/dynamicresource-crash.md
- name: .NET 9
items:
- name: "'GetXmlNamespaceMaps' type change"
Expand Down
55 changes: 55 additions & 0 deletions docs/core/compatibility/wpf/10.0/dynamicresource-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: "Breaking change - Incorrect usage of DynamicResource causes application crash"
description: "Learn about the breaking change in .NET 10 Preview 4 where incorrect usage of DynamicResource now causes application crashes."
ms.date: 5/12/2025
ai-usage: ai-assisted
ms.custom: https://github.com/dotnet/docs/issues/46089
---

# Incorrect usage of DynamicResource causes application crash

Beginning with .NET 10 Preview 4, applications using `DynamicResource` incorrectly now crash at runtime.

## Version introduced

.NET 10 Preview 4

## Previous behavior

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.

## New behavior

Applications now crash with an error similar to the following:

```output
System.Windows.Markup.XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception.
```

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`:

```xml
<SolidColorBrush x:Key="RedColorBrush" Color="#FFFF0000" />
<SolidColorBrush x:Key="ResourceName" Color="{DynamicResource RedColorBrush}" />
```

## Type of breaking change

This is both a [source-incompatible](../../categories.md#source-compatibility) and [behavioral](../../categories.md#behavioral-change) change.

## Reason for change

This change improves the performance of `DynamicResource` usage. The optimization ensures that incorrect resource initialization is caught immediately, preventing unintended behavior.

## Recommended action

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`:

```xml
<Color x:Key="RedColor">#FFFF0000</Color>
<SolidColorBrush x:Key="ResourceName" Color="{DynamicResource RedColor}" />
```

## Affected APIs

None.