{"record":{"id":"32d9d01b277020a2","repo":"dotnet/wpf","slug":"sr-resourcedictionarydeferredcontentfailure","errorCode":null,"errorMessage":"SR.ResourceDictionaryDeferredContentFailure","messagePattern":"SR\\.ResourceDictionaryDeferredContentFailure","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs","lineNumber":1183,"sourceCode":"            IList<KeyRecord> keys = reader.ReadKeys();\n\n            // If we already have the Source set then we can ignore\n            // this deferable content section\n            if (_source == null)\n            {\n                if (_reader == null)\n                {\n                    _reader = reader;\n                    SetKeys(keys, deferrableContent.ServiceProvider);\n                }\n                else\n                {\n                    throw new InvalidOperationException(SR.ResourceDictionaryDuplicateDeferredContent);\n                }\n            }\n            else if (keys.Count > 0)\n            {\n                throw new InvalidOperationException(SR.ResourceDictionaryDeferredContentFailure);\n            }\n        }\n\n        private object GetKeyValue(KeyRecord key, IServiceProvider serviceProvider)\n        {\n            if (key.KeyString != null)\n            {\n                return key.KeyString;\n            }\n            else if (key.KeyType != null)\n            {\n                return key.KeyType;\n            }\n            else\n            {\n                System.Xaml.XamlReader reader = key.KeyNodeList.GetReader();\n                object value = EvaluateMarkupExtensionNodeList(reader, serviceProvider);\n                return value;","sourceCodeStart":1165,"sourceCodeEnd":1201,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/ResourceDictionary.cs#L1165-L1201","documentation":"Thrown as InvalidOperationException from ResourceDictionary.SetDeferrableContent when the dictionary already contains regular (non-deferred) keys but is then given deferred content. A dictionary must be populated either entirely through deferred BAML content or through direct key insertion — mixing both is not supported.","triggerScenarios":"Adding keys (e.g. dict[\"key\"]=value or MergedDictionaries) to a ResourceDictionary and afterwards setting DeferrableContent on it.","commonSituations":"Custom XAML/BAML loading code that pre-populates a dictionary then attaches deferred content; malformed generated dictionaries.","solutions":["Set DeferrableContent before adding any keys to the dictionary","Use a fresh empty ResourceDictionary for deferred content","Never mix programmatic key insertion with deferred BAML content in one dictionary"],"exampleFix":"// before\ndict[\"myKey\"] = myValue;\ndict.DeferrableContent = content; // throws\n// after\ndict.DeferrableContent = content; // set first\n// access keys only through the deferred mechanism","handlingStrategy":"validation","validationCode":"if (dict.Keys.Count > 0) throw new InvalidOperationException(\"Deferred content requires an empty dictionary\");","typeGuard":null,"tryCatchPattern":"try { dict.DeferrableContent = content; } catch (InvalidOperationException) { dict = new ResourceDictionary(); dict.DeferrableContent = content; }","preventionTips":["Set deferred content on a brand-new, empty dictionary","Never mix manual key insertion with BAML deferred content"],"tags":["wpf","resourcedictionary","xaml","deferred-content"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}