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..8b63bec5cecf3 --- /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.