dotnet/wpf · error · InvalidOperationException

SR.BamlReaderNoOwnerType

Error message

SR.BamlReaderNoOwnerType: {0} {1}

What it means

BamlReader.GetPropertyCustomRecordInfo throws this while resolving a custom property record in a BAML stream. It could not determine the OwnerType of the attribute, which is required to reflect over the property. Without an owner type neither a DependencyProperty nor a CLR PropertyInfo can be resolved from the BAML record, so the reader aborts with InvalidOperationException.

Solutions

  1. Ensure the assembly that defines the property's owner type is deployed and referenced (check <Reference> entries and bin output).
  2. Verify the xmlns prefix in the original XAML maps to the correct XmlnsDefinition/assembly; fix the mapping in AssemblyInfo.cs or the xmlns declaration.
  3. Recompile the XAML/BAML with the current WPF SDK so attribute records carry correct owner type/assembly information.
  4. If you own the reader path, check MapTable.GetDependencyProperty for early return and confirm AssemblyName matches the BAML source assembly.

Example fix

// before (missing owner assembly)
<Window xmlns:my="clr-namespace:MyControls" />  // assembly not referenced

// after
<Window xmlns:my="clr-namespace:MyControls;assembly=MyControls" />
// and add <Reference Include="MyControls" /> to the project
Defensive patterns

Strategy: validation

Validate before calling

// before parsing BAML, confirm the owner types/properties resolve
var attrType = Assembly.Load(bamlAssemblyName).GetType(ownerTypeName, throwOnError: false);
if (attrType == null)
    throw new InvalidOperationException($"Owner type '{ownerTypeName}' not loadable; BAML property '{attrName}' cannot be resolved.");

Type guard

bool OwnerTypeResolves(BamlAttributeInfoRecord a) => a.OwnerType != null || a.DP != null || a.PropInfo != null;

Try / catch

try { reader.Read(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("owner")) {
    log.LogError("BAML attribute missing owner type — check assembly references and xmlns mappings.");
}

Prevention

When it happens

Trigger: Reading BAML (compiled XAML in a .baml resource) whose BamlAttributeInfoRecord has null DP and null PropInfo, MapTable.GetDependencyProperty returns null, and the attribute record's OwnerType is still null — i.e. the assembly or type owning the property could not be loaded/mapped.

Common situations: A referenced assembly containing the custom control or attached property is missing at runtime, a BAML stream produced by a mismatched/older compiler version references types not present, or XmlnsDefinition assembly mappings are broken so the owner type never gets set in the map table.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs:990

            BamlPropertyInfo info = new BamlPropertyInfo();

            BamlAttributeInfoRecord attrInfo = SetCommonPropertyInfo(info,
                ((BamlPropertyCustomRecord)_currentBamlRecord).AttributeId);
            info.RecordType = _currentBamlRecord.RecordType;
            info.AttributeUsage = BamlAttributeUsage.Default;

            BamlPropertyCustomRecord bamlRecord = (BamlPropertyCustomRecord)_currentBamlRecord;

            // Reverse the binary data stored in the record into a string by first getting the
            // property.  If it has not already been cached in the attribute info record, then
            // attempt to resolve it as a DependencyProperty or a PropertyInfo.
            if (attrInfo.DP == null && attrInfo.PropInfo == null)
            {
                attrInfo.DP = MapTable.GetDependencyProperty(attrInfo);

                if (attrInfo.OwnerType == null)
                {
                    throw new InvalidOperationException(SR.Format(SR.BamlReaderNoOwnerType, attrInfo.Name, AssemblyName));
                }
                if (attrInfo.DP == null)
                {
                    try
                    {
                        attrInfo.PropInfo = attrInfo.OwnerType.GetProperty(attrInfo.Name,
                                BindingFlags.Instance | BindingFlags.Public);
                    }
                    catch (AmbiguousMatchException)
                    {
                        // Handle ambiguous match just like XamlTypeMapper.PropertyInfoFromName does.
                        // This is for consistency, although it's probably wrong.
                        // The doc for GetProperties says:
                        //      The GetProperties method does not return properties
                        //      in a particular order, such as alphabetical or
                        //      declaration order. Your code must not depend on the
                        //      order in which properties are returned, because that
                        //      order varies.

View on GitHub (pinned to 81131a70a4)