dotnet/wpf · error · XamlParseException

SR.MarkupExtensionDynamicOrBindingInCollection

Error message

SR.MarkupExtensionDynamicOrBindingInCollection

What it means

CheckCanReceiveMarkupExtension allows a markup extension inside a collection only when the extension is a BindingBase and the target property's type is a Collection<BindingBase> (the MultiBinding.Bindings special case). Otherwise it throws this XamlParseException naming the extension type and the collection's type.

Solutions

  1. Use only Binding (or other BindingBase derivatives) inside MultiBinding.Bindings.
  2. Type custom collection properties as Collection<BindingBase> if they must accept bindings.
  3. Move non-binding extensions out of collection properties and apply them elsewhere.
  4. Replace the extension with a concrete value instance added in code.

Example fix

<!-- before -->
<MultiBinding.Bindings>
  <StaticResource ResourceKey="SomeConverterBinding"/>
</MultiBinding.Bindings>
<!-- after -->
<MultiBinding.Bindings>
  <Binding Path="A"/>
  <Binding Path="B"/>
Defensive patterns

Strategy: validation

Validate before calling

static bool IsBindingCollectionProperty(System.Reflection.PropertyInfo p, object ext) =>
    ext is System.Windows.Data.BindingBase &&
    typeof(System.Collections.ObjectModel.Collection<System.Windows.Data.BindingBase>).IsAssignableFrom(p.PropertyType);

Try / catch

try { Helper.CheckCanReceiveMarkupExtension(target, propertyInfo, ext); }
catch (XamlParseException ex) { log.Error($"Invalid extension in collection: {ex.Message}"); }

Prevention

When it happens

Trigger: Placing an extension such as StaticResource or DynamicResource (not a Binding) into a collection property like MultiBinding.Bindings, or putting a Binding into a collection whose type is not Collection<BindingBase>.

Common situations: Adding {StaticResource} entries to MultiBinding.Bindings, custom collection properties typed as List<BindingBase> instead of Collection<BindingBase>, and XAML snippets copied between collection types.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/8384a61df53afd61. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs:685

                                                                targetType.Name));
                        }
                    }
                    else
                    {
                        // This is the Collection ContentProperty case
                        // Example:
                        // <DockPanel>
                        //   <Button />
                        //   <DynamicResource ResourceKey="foo" />
                        // </DockPanel>

                        // Collection<BindingBase> used in MultiBinding is a special
                        // case of a Collection that can contain a Binding.

                        if (!typeof(BindingBase).IsAssignableFrom(markupExtension.GetType()) ||
                            !typeof(Collection<BindingBase>).IsAssignableFrom(targetProperty.GetType()))
                        {
                            throw new XamlParseException(SR.Format(SR.MarkupExtensionDynamicOrBindingInCollection,
                                                                markupExtension.GetType().Name,
                                                                targetProperty.GetType().Name));
                        }
                    }
                }
            }
            else
            {
                // This is the explicit Collection Property case
                // Example:
                // <DockPanel>
                // <DockPanel.Children>
                //   <Button />
                //   <DynamicResource ResourceKey="foo" />
                // </DockPanel.Children>
                // </DockPanel>

                // Collection<BindingBase> used in MultiBinding is a special

View on GitHub (pinned to 81131a70a4)