{"record":{"id":"4fa36ffcf00e7c94","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-unknowntypename","errorCode":null,"errorMessage":"ArgumentNullException(nameof(unknownTypeName))","messagePattern":"ArgumentNullException\\(nameof\\(unknownTypeName\\)\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs","lineNumber":49,"sourceCode":"        private NullableReference<Type> _underlyingType;\n\n        // Lazy init: null until initialized\n        // Thread safety: idempotent, assignment races are okay; do not assign incomplete values\n        private ReadOnlyCollection<string> _namespaces;\n        private ThreeValuedBool _isNameValid;\n\n        protected XamlType(string typeName, IList<XamlType> typeArguments, XamlSchemaContext schemaContext)\n        {\n            _name = typeName ?? throw new ArgumentNullException(nameof(typeName));\n            _schemaContext = schemaContext ?? throw new ArgumentNullException(nameof(schemaContext));\n            _typeArguments = GetTypeArguments(typeArguments);\n        }\n\n        public XamlType(string unknownTypeNamespace, string unknownTypeName, IList<XamlType> typeArguments, XamlSchemaContext schemaContext)\n        {\n            ArgumentNullException.ThrowIfNull(unknownTypeNamespace);\n\n            _name = unknownTypeName ?? throw new ArgumentNullException(nameof(unknownTypeName));\n            _namespaces = new ReadOnlyCollection<string>(new string[] { unknownTypeNamespace });\n            _schemaContext = schemaContext ?? throw new ArgumentNullException(nameof(schemaContext));\n            _typeArguments = GetTypeArguments(typeArguments);\n            _reflector = TypeReflector.UnknownReflector;\n        }\n\n        public XamlType(Type underlyingType, XamlSchemaContext schemaContext)\n            :this(underlyingType, schemaContext, null)\n        {\n        }\n\n        public XamlType(Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker)\n            : this(null, underlyingType, schemaContext, invoker, null)\n        {\n        }\n\n        internal XamlType(string alias, Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker, TypeReflector reflector)\n        {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs#L31-L67","documentation":"The public XamlType(unknownTypeNamespace, unknownTypeName, typeArguments, schemaContext) constructor creates a 'unknown type' placeholder for types that could not be resolved, and requires a non-null unknownTypeName. Null throws ArgumentNullException; the name plus namespace form the identity of the unknown type.","triggerScenarios":"Calling this constructor with unknownTypeName == null, e.g. when propagating a name that failed to parse or was not supplied by the caller reporting the unresolved type.","commonSituations":"Code recording unresolved XAML namespace/type references where the local name was lost during parsing; interop layers forwarding null from external metadata.","solutions":["Supply the actual local type name string, even if the type is unresolved","Use a descriptive placeholder name (e.g. the raw text from the XAML) when the true name is unavailable","Validate the name argument before constructing"],"exampleFix":"// before\nvar t = new XamlType(ns, localName, null, schemaContext); // localName == null\n// after\nvar t = new XamlType(ns, localName ?? \"Unknown\", null, schemaContext);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(unknownTypeName)) throw new ArgumentException(\"unknownTypeName required\", nameof(unknownTypeName));","typeGuard":"bool ok = unknownTypeName is not null;","tryCatchPattern":"try { var t = new XamlType(ns, name, null, ctx); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"unknownTypeName\") { /* fall back to placeholder name */ }","preventionTips":["Pass through the raw local name from XAML even when unresolved","Never forward nullable name variables directly into this constructor","Use \"Unknown\" as last-resort placeholder name"],"tags":["argumentnullexception","constructor","xamltype","xaml"],"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"}