{"record":{"id":"66b0e77701cd8438","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-typename","errorCode":null,"errorMessage":"throw new ArgumentNullException( nameof(typeName));","messagePattern":"throw new ArgumentNullException\\( nameof\\(typeName\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs","lineNumber":2159,"sourceCode":"        ///   The name is of the form prefix:typename, such as MyNs:MyNewButton\n        /// </param>\n        /// <param name=\"element\">\n        ///   A DependencyObject that is logical parent for the type to be resolved.  This\n        ///   is required because it is this element (or its ancestors) that contains\n        ///   namespace mapping data that is needed to resolve the typeName.\n        /// </param>\n        /// <returns>\n        ///  The resolved clr type.  Null if not found\n        /// </returns>\n        internal static Type GetTypeFromName(string typeName, DependencyObject element)\n        {\n            if (element == null)\n            {\n                throw new ArgumentNullException( nameof(element));\n            }\n            if (typeName == null)\n            {\n                throw new ArgumentNullException( nameof(typeName));\n            }\n\n            // Now map the prefix to an xml namespace uri\n            int colonIndex = typeName.IndexOf(':');\n            string prefix = string.Empty;\n            if (colonIndex > 0)\n            {\n                prefix = typeName.Substring(0, colonIndex);\n                typeName = typeName.Substring(colonIndex+1, typeName.Length-colonIndex-1);\n            }\n\n            // First, get the xmlns dictionary to map prefixes to xml namespace uris\n            XmlnsDictionary prefixDictionary = element.GetValue(XmlAttributeProperties.XmlnsDictionaryProperty)\n                                               as XmlnsDictionary;\n\n            object xmlNamespaceObject = prefixDictionary?[prefix];\n\n            // Then get the list of NamespaceMapEntry objects that maps the xml namespace uri to one","sourceCodeStart":2141,"sourceCodeEnd":2177,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapper.cs#L2141-L2177","documentation":"XamlTypeMapper.GetTypeFromName also throws ArgumentNullException when typeName is null. The method parses the name (optionally with an xmlns prefix before ':') and maps it to a CLR type; a null name has nothing to resolve.","triggerScenarios":"Calling GetTypeFromName(null, element) — commonly when a XAML attribute value or element name was absent, or upstream parsing produced a null type string.","commonSituations":"Malformed XAML where a type reference attribute is missing; custom parser code forwarding element names without null checks; deserializing documents with empty type tags.","solutions":["Pass a non-null type name string","Check the attribute/element value for null before calling the resolver","Treat null as 'no type specified' and skip resolution at the call site"],"exampleFix":"// before\nType t = XamlTypeMapper.GetTypeFromName(attr.Value, element); // Value may be null\n// after\nif (!string.IsNullOrEmpty(attr.Value))\n    Type t = XamlTypeMapper.GetTypeFromName(attr.Value, element);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(typeName))\n    return null;\nType t = XamlTypeMapper.GetTypeFromName(typeName, element);","typeGuard":"bool HasTypeName(string typeName) => !string.IsNullOrWhiteSpace(typeName);","tryCatchPattern":"try\n{\n    var t = XamlTypeMapper.GetTypeFromName(typeName, element);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"typeName\")\n{\n    log.LogWarning(\"Missing type name in XAML value; skipping resolution\");\n    t = null;\n}","preventionTips":["Null-check XAML attribute values before type resolution","Treat missing type attributes as 'no type' rather than calling the resolver","Validate source XAML for empty type tags before processing"],"tags":["wpf","xaml","argument-null","type-resolution"],"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"}