{"record":{"id":"8cf4dc90f9edd5dc","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-prefix","errorCode":null,"errorMessage":"ArgumentNullException(nameof(prefix))","messagePattern":"ArgumentNullException\\(nameof\\(prefix\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsPrefixAttribute.cs","lineNumber":40,"sourceCode":"    ///   <code>\n    ///   &lt;Page xmlns:myns=\"http://schemas.fabrikam.com/mynamespace\" .... &gt;\n    ///      &lt;myns:MyButton&gt; ..... &lt;/myns:MyButton&gt;\n    ///   &lt;/Page&gt;\n    ///   </code>\n    /// </summary>\n    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]\n    [TypeForwardedFrom(\"WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\")]\n    public sealed class XmlnsPrefixAttribute : Attribute\n    {\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"xmlNamespace\">XML namespce</param>\n        /// <param name=\"prefix\">recommended prefix</param>\n        public XmlnsPrefixAttribute(string xmlNamespace, string prefix)\n        {\n            XmlNamespace = xmlNamespace ?? throw new ArgumentNullException(nameof(xmlNamespace));\n            Prefix= prefix ?? throw new ArgumentNullException(nameof(prefix));\n        }\n\n        /// <summary>\n        /// XML Namespace\n        /// </summary>\n        public string XmlNamespace { get; }\n\n        /// <summary>\n        /// New Xml Namespace\n        /// </summary>\n        public string Prefix { get; }\n   }\n}\n","sourceCodeStart":22,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsPrefixAttribute.cs#L22-L54","documentation":"XmlnsPrefixAttribute's constructor throws ArgumentNullException when the prefix parameter is null. The prefix is the designer/tooltip recommendation for how to refer to the namespace in XAML; a null prefix is rejected at construction.","triggerScenarios":"Calling new XmlnsPrefixAttribute(someXmlNamespace, null) — an [assembly: XmlnsPrefix] declaration whose second argument is null.","commonSituations":"Generated or hand-written assembly attributes where the prefix string variable was never assigned; copy-paste mistakes in AssemblyInfo.cs.","solutions":["Pass a non-null short identifier string (e.g. \"controls\") as the prefix argument.","If the prefix comes from a variable or config, guard against null before constructing the attribute.","Keep prefix and XmlnsDefinition namespace strings in shared constants to avoid mismatches."],"exampleFix":"// before\n[assembly: XmlnsPrefix(\"http://schemas.myapp.com/controls\", null)]\n// after\n[assembly: XmlnsPrefix(\"http://schemas.myapp.com/controls\", \"controls\")]","handlingStrategy":"validation","validationCode":"if (prefix is null) throw new ArgumentException(\"prefix must be non-null\", nameof(prefix));\nvar attr = new XmlnsPrefixAttribute(xmlNamespace, prefix);","typeGuard":"bool HasPrefix(string? prefix) => !string.IsNullOrEmpty(prefix);","tryCatchPattern":"try { var attr = new XmlnsPrefixAttribute(ns, prefix); }\ncatch (ArgumentNullException ex) { /* ex.ParamName == \"prefix\": use a default prefix */ }","preventionTips":["Choose short literal prefixes (e.g. \"controls\", \"props\") directly in the attribute.","Centralize prefix and namespace pairs in one constants file.","Keep designer tooling in sync: regenerate attributes after namespace changes."],"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-21T21:30:21.729Z"}