# System.Windows.Markup.XamlParseException: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '42' and line position '10'.

- **ID:** `dotnet/wpf-resource-dictionary-key-not-found`
- **Domain:** dotnet
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A StaticResource reference in WPF XAML points to a resource key that is not defined in any merged ResourceDictionary or is defined later in the same dictionary, causing a lookup failure at runtime.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| WPF on .NET Core 3.1 | active | — | — |
| WPF on .NET 5.0 | active | — | — |
| WPF on .NET 6.0 | active | — | — |
| WPF on .NET 7.0 | active | — | — |
| WPF on .NET 8.0 | active | — | — |
| .NET Framework 4.7.2 | active | — | — |
| .NET Framework 4.8 | active | — | — |

## Workarounds

1. **Define the missing resource key in the correct ResourceDictionary. For example, in App.xaml: <Application.Resources><ResourceDictionary><SolidColorBrush x:Key="MyBrush" Color="Blue"/></ResourceDictionary></Application.Resources>** (95% success)
   ```
   Define the missing resource key in the correct ResourceDictionary. For example, in App.xaml: <Application.Resources><ResourceDictionary><SolidColorBrush x:Key="MyBrush" Color="Blue"/></ResourceDictionary></Application.Resources>
   ```
2. **Ensure resource dictionaries are merged in the correct order. The resource must be defined before it is referenced. Move the resource definition above the element that uses it in the same file or merge dictionaries in the correct sequence.** (90% success)
   ```
   Ensure resource dictionaries are merged in the correct order. The resource must be defined before it is referenced. Move the resource definition above the element that uses it in the same file or merge dictionaries in the correct sequence.
   ```
3. **Use DynamicResource as a temporary workaround if the resource is defined but not available at load time (e.g., defined in a merged dictionary that is loaded later). However, prefer fixing the StaticResource lookup.** (70% success)
   ```
   Use DynamicResource as a temporary workaround if the resource is defined but not available at load time (e.g., defined in a merged dictionary that is loaded later). However, prefer fixing the StaticResource lookup.
   ```

## Dead Ends

- **Changing StaticResource to DynamicResource everywhere.** — DynamicResource resolves at runtime but may cause performance issues and still fail if the resource is never defined; it also changes the behavior of resource updates. (70% fail)
- **Adding the resource key with a null value in the same dictionary.** — A null resource will cause a NullReferenceException when used; it does not solve the missing definition issue. (90% fail)
- **Deleting the XAML file and recreating it from scratch.** — This is an overreaction; the root cause is a missing resource definition, not file corruption. (100% fail)
