{"record":{"id":"d5ccf4db1a8d99ca","repo":"dotnet/wpf","slug":"sr-markupextensiondynamicorbindingonclrprop","errorCode":null,"errorMessage":"SR.MarkupExtensionDynamicOrBindingOnClrProp","messagePattern":"SR\\.MarkupExtensionDynamicOrBindingOnClrProp","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs","lineNumber":664,"sourceCode":"                        else\n                        {\n                            MethodInfo methodInfo = (MethodInfo)targetMember;\n                            ParameterInfo[] parameterInfos = methodInfo.GetParameters();\n                            Debug.Assert(parameterInfos.Length == 2, \"The signature of a static settor must contain two parameters\");\n                            memberType = parameterInfos[1].ParameterType;\n                        }\n\n                        // Check if the MarkupExtensionType is assignable to the given MemberType\n                        // This check is to allow properties such as the following\n                        // - DataTrigger.Binding\n                        // - Condition.Binding\n                        // - HierarchicalDataTemplate.ItemsSource\n                        // - GridViewColumn.DisplayMemberBinding\n\n                        if (!typeof(MarkupExtension).IsAssignableFrom(memberType) ||\n                             !memberType.IsAssignableFrom(markupExtension.GetType()))\n                        {\n                            throw new XamlParseException(SR.Format(SR.MarkupExtensionDynamicOrBindingOnClrProp,\n                                                                markupExtension.GetType().Name,\n                                                                targetMember.Name,\n                                                                targetType.Name));\n                        }\n                    }\n                    else\n                    {\n                        // This is the Collection ContentProperty case\n                        // Example:\n                        // <DockPanel>\n                        //   <Button />\n                        //   <DynamicResource ResourceKey=\"foo\" />\n                        // </DockPanel>\n\n                        // Collection<BindingBase> used in MultiBinding is a special\n                        // case of a Collection that can contain a Binding.\n\n                        if (!typeof(BindingBase).IsAssignableFrom(markupExtension.GetType()) ||","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs#L646-L682","documentation":"Helper.CheckCanReceiveMarkupExtension validates that a markup extension can be applied to a target member. When the target is a plain CLR property (not a DependencyProperty) and the member type does not accept the extension's type, it throws this XamlParseException naming the extension, member, and target type.","triggerScenarios":"Applying a Binding/StaticResource/DynamicResource-style extension to a non-dependency CLR property whose type is not MarkupExtension-compatible, e.g. a Binding on a plain C# property set in XAML where the property type is not assignable from the extension.","commonSituations":"Adding bindings to view-model-facing CLR properties in XAML, custom controls exposing plain properties expecting dynamic values, and migrating WinForms-style properties to XAML without converting them to dependency properties.","solutions":["Convert the target property to a DependencyProperty (register with DependencyProperty.Register) so extensions can bind to it.","Remove the markup extension and assign the value directly in code or via a setter.","Ensure the property type is compatible with the extension (e.g. Binding targets must be dependency properties).","Use the documented special cases (HierarchicalDataTemplate.ItemsSource, GridViewColumn.DisplayMemberBinding) only as designed."],"exampleFix":"// before\npublic string Title { get; set; }  // XAML: Title=\"{Binding Path=Name}\"\n// after\npublic static readonly DependencyProperty TitleProperty =\n    DependencyProperty.Register(\"Title\", typeof(string), typeof(MyControl));\npublic string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } }","handlingStrategy":"validation","validationCode":"static bool CanReceiveMarkup(DependencyObject target, string prop, object ext)\n{\n    var pi = target.GetType().GetProperty(prop);\n    if (pi == null) return false;\n    return pi.GetValue(target) is DependencyProperty backerOrDp == false\n        ? typeof(MarkupExtension).IsAssignableFrom(pi.PropertyType) &&\n          pi.PropertyType.IsInstanceOfType(ext)\n        : true;\n}","typeGuard":null,"tryCatchPattern":"try { Helper.CheckCanReceiveMarkupExtension(target, propertyInfo, ext); }\ncatch (XamlParseException ex) { log.Error($\"Extension {ex.Message} not allowed on CLR property\"); }","preventionTips":["Expose bindable properties as DependencyProperties.","Never put Binding/StaticResource/DynamicResource on plain CLR properties in XAML.","Keep extension target types MarkupExtension-compatible when designing APIs."],"tags":["wpf","xaml","markup-extension","dependency-property"],"backgroundTag":"incompatible-source-type","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"}