From 06ff665c7b0ea3b844e84c465cdeca28419afe58 Mon Sep 17 00:00:00 2001 From: Cam Date: Mon, 12 May 2025 23:22:01 +0000 Subject: [PATCH 1/2] [Breaking change]: Crashes due to incorrect usage of `DyanmicResource`'s Fixes #46089 --- docs/core/compatibility/10.0.md | 6 ++ docs/core/compatibility/toc.yml | 8 +++ .../wpf/10.0/dynamicresource-crash.md | 55 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 docs/core/compatibility/wpf/10.0/dynamicresource-crash.md diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index e9ac7d2247509..b727a40ef9c04 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -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 | diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index 9a68a1eeca6c4..c6139d34c74ae 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -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 @@ -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" diff --git a/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md b/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md new file mode 100644 index 0000000000000..38e09c0488750 --- /dev/null +++ b/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md @@ -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 + + +``` + +## 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 +#FFFF0000 + +``` + +## Affected APIs + +None. From fd6688e95c3511a659bde36e0ec031bfdb0cbf10 Mon Sep 17 00:00:00 2001 From: "Andy (Steve) De George" <67293991+adegeo@users.noreply.github.com> Date: Mon, 12 May 2025 16:43:27 -0700 Subject: [PATCH 2/2] Remove quote that snuck in --- docs/core/compatibility/wpf/10.0/dynamicresource-crash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md b/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md index 38e09c0488750..8b63bec5cecf3 100644 --- a/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md +++ b/docs/core/compatibility/wpf/10.0/dynamicresource-crash.md @@ -6,7 +6,7 @@ ai-usage: ai-assisted ms.custom: https://github.com/dotnet/docs/issues/46089 --- -# Incorrect usage of DynamicResource causes application crash" +# Incorrect usage of DynamicResource causes application crash Beginning with .NET 10 Preview 4, applications using `DynamicResource` incorrectly now crash at runtime.