{"record":{"id":"e5df533bec820a10","repo":"dotnet/wpf","slug":"sr-bamlbadextensionvalue","errorCode":null,"errorMessage":"SR.BamlBadExtensionValue","messagePattern":"SR\\.BamlBadExtensionValue","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs","lineNumber":2391,"sourceCode":"            string valuePrefix = null;\n            string typeName = null;\n            string propName = null;\n\n            if (memberId < 0)\n            {\n                memberId = (short)-memberId;\n                DependencyProperty dp = null;\n                if (memberId < (short)KnownProperties.MaxDependencyProperty)\n                {\n                    KnownProperties knownId = (KnownProperties)(memberId);\n                    {\n                        dp = KnownTypes.GetKnownDependencyPropertyFromId(knownId);\n                    }\n                }\n\n                if (dp == null)\n                {\n                    throw new InvalidOperationException(SR.BamlBadExtensionValue);\n                }\n                else\n                {\n                    typeName = dp.OwnerType.Name;\n                    propName = dp.Name;\n                }\n\n                object prefixObject = _prefixDictionary[XamlReaderHelper.DefaultNamespaceURI];\n                valuePrefix = (prefixObject == null) ? string.Empty : (string)prefixObject;\n            }\n            else\n            {\n                BamlAttributeInfoRecord attrInfo = MapTable.GetAttributeInfoFromId(memberId);\n                BamlTypeInfoRecord valueTypeInfo = MapTable.GetTypeInfoFromId(attrInfo.OwnerTypeId);\n                string valueXmlNamespace;\n                string valueAssemblyName;\n                GetAssemblyAndPrefixAndXmlns(valueTypeInfo, out valueAssemblyName, out valuePrefix, out valueXmlNamespace);\n                typeName = valueTypeInfo.TypeFullName;","sourceCodeStart":2373,"sourceCodeEnd":2409,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs#L2373-L2409","documentation":"BamlReader throws InvalidOperationException(SR.BamlBadExtensionValue) while resolving a markup-extension property from BAML when the referenced known property ID does not map to a DependencyProperty (dp stays null after KnownTypes lookup). It means the compiled BAML references a property the reader cannot resolve to a known DependencyProperty, so the reader cannot compute owner/property names.","triggerScenarios":"Reading compiled BAML whose PropertyRecord resolves via a KnownTypes ID to a non-dependency-property (or an unknown ID), leaving dp == null in ReadPropertyExtensionRecord/related extension-value handling in BamlReader.cs.","commonSituations":"BAML compiled by a mismatched or older/newer WPF toolchain (known-type table out of sync), hand-modified or corrupted BAML, or markup extensions targeting properties that are not DependencyProperties after refactoring.","solutions":["Recompile the XAML/BAML with the same .NET/WPF version used at runtime so KnownTypes IDs match","Verify the targeted property is a DependencyProperty (replaces other property kinds after refactors)","Regenerate/rebuild the assembly containing the BAML instead of editing it","If loading loose XAML, use XamlReader with a matching SchemaContext instead of BamlReader"],"exampleFix":"// before: markup extension set on a plain CLR property\n<Label MyThing=\"{StaticResource x}\" />\n// after: target a DependencyProperty\n<Label Content=\"{StaticResource x}\" />","handlingStrategy":"try-catch","validationCode":"// ensure markup extension targets a DependencyProperty before compiling/loading\nvar prop = typeof(MyControl).GetProperty(nameof(MyControl.MyProp));\nif (DependencyProperty.FromName(nameof(MyControl.MyProp), typeof(MyControl)) == null)\n    throw new InvalidOperationException(\"Target must be a DependencyProperty\");","typeGuard":"static bool IsDependencyProperty(Type t, string name) =>\n    DependencyProperty.FromName(name, t) != null;","tryCatchPattern":"try { LoadBaml(stream); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"extension\")) {\n    // recompile BAML with matching framework, or fix the extension target property\n}","preventionTips":["Build and run on the same .NET/WPF version","Never hand-edit compiled BAML","Confirm markup-extension targets are DependencyProperties after refactors"],"tags":["wpf","baml","markup-extension","invalid-operation"],"backgroundTag":"internal-invariant-violation","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"}