dotnet/wpf · error · ArgumentNullException

throw new ArgumentNullException( nameof(ownerType));

Error message

throw new ArgumentNullException( nameof(ownerType));

What it means

Inside XamlTypeMapper's GetDependencyProperty-style logic (#if DEBUG-style public surface ending in DependencyProperty.FromName), ownerType is validated after optional resolution from typeAndSerializer, and ArgumentNullException is thrown if it is still null. DependencyProperty.FromName requires a concrete owner Type to search for the property.

Solutions

  1. Pass a valid Type as ownerType
  2. If relying on type resolution, ensure the type data actually resolved before calling (check ObjectType != null)
  3. Use typeof(OwnerClass) directly when the owner is known at compile time

Example fix

// before
var dp = mapper.GetPropertyName(localName, null);
// after
var dp = DependencyProperty.FromName(localName, typeof(OwnerClass));
Defensive patterns

Strategy: validation

Validate before calling

if (ownerType == null)
    ownerType = typeof(DependencyObject); // or fail with a clear message
var dp = DependencyProperty.FromName(localName, ownerType);

Type guard

bool HasResolvedOwner(Type ownerType) => ownerType != null && !ownerType.ContainsGenericParameters;

Try / catch

try
{
    var dp = DependencyProperty.FromName(localName, ownerType);
}
catch (ArgumentNullException ex) when (ex.ParamName == "ownerType")
{
    log.LogError("Owner type unresolved for property {Name}", localName);
}

Prevention

When it happens

Trigger: Calling the API with a null ownerType directly, or with data that failed to resolve (typeAndSerializer.ObjectType returned null) leaving ownerType null at the check.

Common situations: Designer code resolving attached property names; property grid tooling looking up DPs where type metadata was missing or the type failed to load.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs:1785

            // this class name as the owner type and return it.  Otherwise just use the
            // passed name and owner.
            int lastIndex = localName.LastIndexOf('.');
            if (-1 != lastIndex)
            {
                string globalClassName = localName.Substring(0,lastIndex);
                localName = localName.Substring(lastIndex+1);
                TypeAndSerializer typeAndSerializer =
                    GetTypeOnly(xmlNamespace, globalClassName);
                if (typeAndSerializer == null || typeAndSerializer.ObjectType == null)
                {
                    ThrowException(nameof(SR.ParserNoType), globalClassName);
                }
                ownerType = typeAndSerializer.ObjectType;
            }

            if(null == ownerType)
            {
                throw new ArgumentNullException( nameof(ownerType));
            }

            return DependencyProperty.FromName(localName, ownerType);
        }

#endif

        /// <summary>
        /// Return the property that has an attached XmlLang attribute.  This identifies this
        /// property as being the one to receive xml:lang attribute values when parsing, or
        /// the holder of the CultureInfo related string.  The XamlTypeMapper caches this
        /// along with the TypeAndSerializer information for fast retrieval.
        /// </summary>
        internal PropertyInfo GetXmlLangProperty(
                string    xmlNamespace,     // xml namespace for the type
                string    localName)        // local name of the type without any '.'
        {
            TypeAndSerializer typeAndSerializer = GetTypeOnly(xmlNamespace, localName);

View on GitHub (pinned to 81131a70a4)