{"record":{"id":"baf3b64831a1aa05","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-ownertype","errorCode":null,"errorMessage":"throw new ArgumentNullException( nameof(ownerType));","messagePattern":"throw new ArgumentNullException\\( nameof\\(ownerType\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":1785,"sourceCode":"            // this class name as the owner type and return it.  Otherwise just use the\n            // passed name and owner.\n            int lastIndex = localName.LastIndexOf('.');\n            if (-1 != lastIndex)\n            {\n                string globalClassName = localName.Substring(0,lastIndex);\n                localName = localName.Substring(lastIndex+1);\n                TypeAndSerializer typeAndSerializer =\n                    GetTypeOnly(xmlNamespace, globalClassName);\n                if (typeAndSerializer == null || typeAndSerializer.ObjectType == null)\n                {\n                    ThrowException(nameof(SR.ParserNoType), globalClassName);\n                }\n                ownerType = typeAndSerializer.ObjectType;\n            }\n\n            if(null == ownerType)\n            {\n                throw new ArgumentNullException( nameof(ownerType));\n            }\n\n            return DependencyProperty.FromName(localName, ownerType);\n        }\n\n#endif\n\n        /// <summary>\n        /// Return the property that has an attached XmlLang attribute.  This identifies this\n        /// property as being the one to receive xml:lang attribute values when parsing, or\n        /// the holder of the CultureInfo related string.  The XamlTypeMapper caches this\n        /// along with the TypeAndSerializer information for fast retrieval.\n        /// </summary>\n        internal PropertyInfo GetXmlLangProperty(\n                string    xmlNamespace,     // xml namespace for the type\n                string    localName)        // local name of the type without any '.'\n        {\n            TypeAndSerializer typeAndSerializer = GetTypeOnly(xmlNamespace, localName);","sourceCodeStart":1767,"sourceCodeEnd":1803,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L1767-L1803","documentation":"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.","triggerScenarios":"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.","commonSituations":"Designer code resolving attached property names; property grid tooling looking up DPs where type metadata was missing or the type failed to load.","solutions":["Pass a valid Type as ownerType","If relying on type resolution, ensure the type data actually resolved before calling (check ObjectType != null)","Use typeof(OwnerClass) directly when the owner is known at compile time"],"exampleFix":"// before\nvar dp = mapper.GetPropertyName(localName, null);\n// after\nvar dp = DependencyProperty.FromName(localName, typeof(OwnerClass));","handlingStrategy":"validation","validationCode":"if (ownerType == null)\n    ownerType = typeof(DependencyObject); // or fail with a clear message\nvar dp = DependencyProperty.FromName(localName, ownerType);","typeGuard":"bool HasResolvedOwner(Type ownerType) => ownerType != null && !ownerType.ContainsGenericParameters;","tryCatchPattern":"try\n{\n    var dp = DependencyProperty.FromName(localName, ownerType);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"ownerType\")\n{\n    log.LogError(\"Owner type unresolved for property {Name}\", localName);\n}","preventionTips":["Confirm type resolution succeeded before reading ObjectType","Pass typeof(T) explicitly when the owner is statically known","Reject unresolved type metadata early with a descriptive error"],"tags":["wpf","dependency-property","argument-null"],"backgroundTag":"null-argument","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"}