{"record":{"id":"6519349cbcb4b30e","repo":"dotnet/wpf","slug":"sr-parsercantgetdporpi-0","errorCode":null,"errorMessage":"SR.ParserCantGetDPOrPi: {0}","messagePattern":"SR\\.ParserCantGetDPOrPi: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs","lineNumber":1026,"sourceCode":"                        //      order varies.\n                        // It's probably more correct to walk up the base class\n                        // tree calling GetProperty with the DeclaredOnly flag.\n\n                        PropertyInfo[] infos = attrInfo.OwnerType.GetProperties(\n                                      BindingFlags.Instance | BindingFlags.Public);\n                        for (int i = 0; i < infos.Length; i++)\n                        {\n                            if (infos[i].Name == attrInfo.Name)\n                            {\n                                attrInfo.PropInfo = infos[i];\n                                break;\n                            }\n                        }\n                    }\n\n                    if (attrInfo.PropInfo == null)\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.ParserCantGetDPOrPi, info.Name));\n                    }\n                }\n            }\n\n            // If we have a property, then get its type and call GetCustomValue,\n            // which uses the XamlSerializer to turn the binary data into a\n            // real object\n            Type propertyType = attrInfo.GetPropertyType();\n            string propertyName = attrInfo.Name;\n            short sid = bamlRecord.SerializerTypeId;\n\n            // if a Setter of Trigger's Property property is being set, then its value is always\n            // a DP. Get the attribInfo of this DP property from the ValueId read into the custom\n            // property record and resolve it into an actual DP instance.\n            if (sid == (short)KnownElements.DependencyPropertyConverter)\n            {\n                Type declaringType = null;\n                _propertyDP = _bamlRecordReader.GetCustomDependencyPropertyValue(bamlRecord, out declaringType);","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs#L1008-L1044","documentation":"BamlReader.GetPropertyCustomRecordInfo throws this when a BAML attribute record resolves to neither a DependencyProperty nor a CLR PropertyInfo. The reader reflected over attrInfo.OwnerType for the property name and found no match, so the property in the BAML stream cannot be applied and parsing fails with InvalidOperationException.","triggerScenarios":"Reading BAML where attrInfo.DP was null and OwnerType.GetProperty(attrInfo.Name) returned null — the named property does not exist on the owner type (renamed, removed, or from a different version of the assembly).","commonSituations":"Runtime references a different version of a control library than the one the XAML was compiled against (property was renamed or deleted); partial-trust reflection failing to see the property; typo scenarios baked into old compiled BAML after an API breaking change.","solutions":["Rebuild the project so the BAML is regenerated against the currently referenced assembly versions.","Restore the missing/renamed property on the owner type or add a compatibility property.","Pin the dependency assembly to the exact version the XAML was compiled against (binding redirect or explicit reference).","Check that the property is public and settable (get/set accessors) so GetProperty can find it."],"exampleFix":"// before: property removed in v2 of the library\npublic class MyControl { /* Text renamed to Caption */ }\n\n// after\npublic class MyControl {\n    public string Caption { get; set; }\n    [Obsolete(\"Use Caption\")]\n    public string Text { get => Caption; set => Caption = value; }\n}","handlingStrategy":"validation","validationCode":"// verify the property exists on the owner type before reading BAML referencing it\nvar pi = ownerType.GetProperty(attrName, BindingFlags.Public | BindingFlags.Instance);\nif (pi == null && DependencyPropertyHelper.GetValueSource(owner, dp).BaseValueSource == BaseValueSource.Unknown)\n    throw new InvalidOperationException($\"'{ownerType.Name}.{attrName}' does not exist at runtime; rebuild BAML against current assemblies.\");","typeGuard":"bool PropertyResolves(Type ownerType, string name) =>\n    ownerType != null && (ownerType.GetProperty(name) != null ||\n        ownerType.GetFields(BindingFlags.Public | BindingFlags.Static).Any(f => f.FieldType == typeof(DependencyProperty) && f.Name == name + \"Property\"));","tryCatchPattern":"try { reader.Read(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"DP\") || ex.Message.Contains(\"property\")) {\n    log.LogError($\"BAML property '{info?.Name}' no longer exists on its owner type — version mismatch.\");\n}","preventionTips":["Pin dependency versions with explicit references/binding redirects.","Never delete public properties used in XAML without a compatibility shim.","Recompile all XAML after upgrading control libraries.","CI check: load all compiled BAML resources in a smoke test."],"tags":["wpf","baml","reflection","version-mismatch"],"backgroundTag":"record-not-found","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"}