{"record":{"id":"638eace63eeb0387","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-clrnamespace-638eac","errorCode":null,"errorMessage":"ArgumentNullException(nameof(clrNamespace))","messagePattern":"ArgumentNullException\\(nameof\\(clrNamespace\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsDefinitionAttribute.cs","lineNumber":49,"sourceCode":"    ///   /Page\n    /// </summary>\n    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]\n    [TypeForwardedFrom(\"WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\")]\n    public sealed class XmlnsDefinitionAttribute : Attribute\n    {\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"xmlNamespace\">\n        /// XmlNamespace used by Markup file\n        /// </param>\n        /// <param name=\"clrNamespace\">\n        /// Clr namespace which contains known types that are used by Markup File.\n        /// </param>\n        public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)\n        {\n            XmlNamespace = xmlNamespace ?? throw new ArgumentNullException(nameof(xmlNamespace));\n            ClrNamespace = clrNamespace ?? throw new ArgumentNullException(nameof(clrNamespace));\n        }\n\n        /// <summary>\n        /// XmlNamespace which can be used in Markup file.\n        /// such as XmlNamespace is set to\n        /// \"http://schemas.fabrikam.com/mynamespace\".\n        ///\n        /// The markup file can have definition like\n        /// xmlns:myns=\"http://schemas.fabrikam.com/mynamespace\"\n        /// </summary>\n        public string XmlNamespace { get; }\n\n        /// <summary>\n        /// ClrNamespace which map to XmlNamespace.\n        /// This ClrNamespace should contain some types which are used\n        /// by Xaml markup file.\n        /// </summary>\n        public string ClrNamespace { get; }","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsDefinitionAttribute.cs#L31-L67","documentation":"The XmlnsDefinitionAttribute constructor throws ArgumentNullException when the clrNamespace parameter is null. The CLR namespace is the target of the XAML namespace mapping; without it the attribute cannot tell the XAML processor where to look for types.","triggerScenarios":"Calling new XmlnsDefinitionAttribute(someXmlNamespace, null) — an assembly-level mapping whose second argument is null.","commonSituations":"Typo or refactoring removed the CLR namespace string in AssemblyInfo.cs; generated code passing an uninitialized namespace variable.","solutions":["Pass a non-null CLR namespace string (e.g. \"MyApp.Controls\") as the second constructor argument.","Verify the namespace actually exists in the assembly so the mapping resolves types.","If the value is computed, add a null check/guard before constructing the attribute."],"exampleFix":"// before\n[assembly: XmlnsDefinition(\"http://schemas.myapp.com/controls\", null)]\n// after\n[assembly: XmlnsDefinition(\"http://schemas.myapp.com/controls\", \"MyApp.Controls\")]","handlingStrategy":"validation","validationCode":"if (clrNamespace is null) throw new ArgumentException(\"clrNamespace must be non-null\", nameof(clrNamespace));\nvar attr = new XmlnsDefinitionAttribute(xmlNamespace, clrNamespace);","typeGuard":"bool IsValidClrNamespace(string? clr) => !string.IsNullOrEmpty(clr);","tryCatchPattern":"try { var attr = new XmlnsDefinitionAttribute(ns, clr); }\ncatch (ArgumentNullException ex) { /* ex.ParamName == \"clrNamespace\": fix or skip mapping */ }","preventionTips":["Keep CLR namespace strings as compile-time constants next to the types they reference.","Add a reflection-based test asserting every XmlnsDefinitionAttribute maps to an existing namespace.","Avoid refactoring namespaces without updating assembly attributes."],"tags":["wpf","xaml","null-argument","attribute"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}