{
  "id": "dotnet/wpf-resource-dictionary-key-not-found",
  "signature": "System.Windows.Markup.XamlParseException: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '42' and line position '10'.",
  "signature_zh": "System.Windows.Markup.XamlParseException: “Provide value on 'System.Windows.StaticResourceExtension'”引发了异常。行号“42”，行位置“10”。",
  "regex": "System\\.Windows\\.Markup\\.XamlParseException: 'Provide value on 'System\\.Windows\\.StaticResourceExtension' threw an exception\\.' Line number '\\d+' and line position '\\d+'\\.",
  "domain": "dotnet",
  "category": "resource_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "WPF XAML 中的 StaticResource 引用指向了一个未在任何合并的 ResourceDictionary 中定义的资源键，或者在同一字典中定义得太晚，导致运行时查找失败。",
  "versions": [
    {
      "version": "WPF on .NET Core 3.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "WPF on .NET 5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "WPF on .NET 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "WPF on .NET 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "WPF on .NET 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET Framework 4.7.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET Framework 4.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Changing StaticResource to DynamicResource everywhere.",
      "why_fails": "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.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding the resource key with a null value in the same dictionary.",
      "why_fails": "A null resource will cause a NullReferenceException when used; it does not solve the missing definition issue.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Deleting the XAML file and recreating it from scratch.",
      "why_fails": "This is an overreaction; the root cause is a missing resource definition, not file corruption.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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>",
      "success_rate": 0.95,
      "how": "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>",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.9,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "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.",
      "success_rate": 0.7,
      "how": "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.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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>",
    "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.",
    "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."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/resources-overview?view=netdesktop-8.0",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-08",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}