{"record":{"id":"6511a40e6e482ba9","repo":"dotnet/wpf","slug":"sr-referenceisnull","errorCode":null,"errorMessage":"SR.ReferenceIsNull","messagePattern":"SR\\.ReferenceIsNull","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs","lineNumber":279,"sourceCode":"\n            if (XamlLanguage.XamlNamespaces.Contains(xamlNamespace))\n            {\n                return XamlLanguage.LookupXamlDirective(name);\n            }\n            else if (XamlLanguage.XmlNamespaces.Contains(xamlNamespace))\n            {\n                return XamlLanguage.LookupXmlDirective(name);\n            }\n\n            return null;\n        }\n\n        public XamlType GetXamlType(XamlTypeName xamlTypeName)\n        {\n            ArgumentNullException.ThrowIfNull(xamlTypeName);\n            if (xamlTypeName.Name is null)\n            {\n                throw new ArgumentException(SR.Format(SR.ReferenceIsNull, \"xamlTypeName.Name\"), nameof(xamlTypeName));\n            }\n\n            if (xamlTypeName.Namespace is null)\n            {\n                throw new ArgumentException(SR.Format(SR.ReferenceIsNull, \"xamlTypeName.Namespace\"), nameof(xamlTypeName));\n            }\n\n            XamlType[] typeArgs = null;\n            if (xamlTypeName.HasTypeArgs)\n            {\n                typeArgs = new XamlType[xamlTypeName.TypeArguments.Count];\n                for (int i = 0; i < xamlTypeName.TypeArguments.Count; i++)\n                {\n                    if (xamlTypeName.TypeArguments[i] is null)\n                    {\n                        throw new ArgumentException(SR.Format(SR.CollectionCannotContainNulls, \"xamlTypeName.TypeArguments\"));\n                    }\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlSchemaContext.cs#L261-L297","documentation":"XamlSchemaContext.GetXamlType(XamlTypeName) validates that the type name's Name property is non-null before resolving. A XamlTypeName with a null Name cannot denote a type, so an ArgumentException naming the offending member is thrown.","triggerScenarios":"Calling schemaContext.GetXamlType(new XamlTypeName(ns, null)) or passing a XamlTypeName constructed/parsed such that Name is null (e.g. default-constructed then partially filled).","commonSituations":"Manually building XamlTypeName instances; parsing prefix strings where the local-name portion was empty; refactoring code that previously supplied both namespace and name.","solutions":["Ensure XamlTypeName is constructed with a non-null local name","Validate xamlTypeName.Name before calling GetXamlType","Use XamlTypeName.Parse with a well-formed 'prefix:localName' string"],"exampleFix":"// before\nvar xn = new XamlTypeName(\"http://schemas.microsoft.com/winfx/2006/xaml\", null);\nschemaContext.GetXamlType(xn);\n// after\nvar xn = new XamlTypeName(\"http://schemas.microsoft.com/winfx/2006/xaml\", \"NullExtension\");\nschemaContext.GetXamlType(xn);","handlingStrategy":"validation","validationCode":"if (xamlTypeName is null || xamlTypeName.Name is null) throw new ArgumentException(\"xamlTypeName must have a Name\");","typeGuard":"bool HasName(XamlTypeName t) => t?.Name is not null;","tryCatchPattern":"try { var xt = ctx.GetXamlType(xtn); } catch (ArgumentException ex) when (ex.ParamName == \"xamlTypeName\") { /* handle missing Name */ }","preventionTips":["Always construct XamlTypeName with both namespace and local name","Validate parsed names before resolving"],"tags":["xaml","argument-null","validation","wpf"],"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"}