{"record":{"id":"9d69945352433df0","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-oldnamespace","errorCode":null,"errorMessage":"ArgumentNullException(nameof(oldNamespace))","messagePattern":"ArgumentNullException\\(nameof\\(oldNamespace\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs","lineNumber":31,"sourceCode":"    ///\n    ///    \"http://schemas.example.com/2003/mynamespace\"\n    ///\n    /// is changed to\n    ///\n    ///    \"http://schemas.example.com/2005/mynamespace\"\n    /// </summary>\n    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]\n    [TypeForwardedFrom(\"WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\")]\n    public sealed class XmlnsCompatibleWithAttribute : Attribute\n    {\n        /// <summary>\n        /// Constructor\n        /// </summary>\n        /// <param name=\"oldNamespace\">old Xml namespce</param>\n        /// <param name=\"newNamespace\">new xml namespace</param>\n        public XmlnsCompatibleWithAttribute(string oldNamespace, string newNamespace)\n        {\n            OldNamespace = oldNamespace ?? throw new ArgumentNullException(nameof(oldNamespace));\n            NewNamespace = newNamespace ?? throw new ArgumentNullException(nameof(newNamespace));\n        }\n\n        /// <summary>\n        /// Old Xml Namespace\n        /// </summary>\n        public string OldNamespace { get; }\n\n        /// <summary>\n        /// New Xml Namespace\n        /// </summary>\n        public string NewNamespace { get; }\n   }\n}\n","sourceCodeStart":13,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs#L13-L46","documentation":"The XmlnsCompatibleWithAttribute constructor throws ArgumentNullException when oldNamespace is null. This attribute declares that an old XML namespace is subsumed by a new one; the old namespace identifier is the core datum, so null is rejected at construction.","triggerScenarios":"Executing new XmlnsCompatibleWithAttribute(null, \"http://new-namespace\") from assembly attribute metadata or reflection-driven code.","commonSituations":"Generating compatibility attributes from config where the old-namespace entry is missing; merging assembly info files and dropping the old namespace value.","solutions":["Pass the full old namespace URI string, e.g. \"http://schemas.example.com/2006/xaml\".","Validate the config/source string for null before constructing the attribute.","Use string constants from a shared namespace definitions file to avoid typos/nulls.","Catch ArgumentNullException if attribute inputs are untrusted metadata."],"exampleFix":"// before\nvar attr = new XmlnsCompatibleWithAttribute(GetOldNs(), newNs); // GetOldNs() null\n// after\nvar oldNs = GetOldNs() ?? \"http://schemas.example.com/2006/xaml\";\nvar attr = new XmlnsCompatibleWithAttribute(oldNs, newNs);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(oldNamespace)) throw new ArgumentException(\"oldNamespace is required.\");\nvar attr = new XmlnsCompatibleWithAttribute(oldNamespace, newNamespace);","typeGuard":null,"tryCatchPattern":"try { attr = new XmlnsCompatibleWithAttribute(oldNs, newNs); }\ncatch (ArgumentNullException ex) { log.Error($\"Bad xmlns compatibility metadata: {ex.ParamName}\"); attr = null; }","preventionTips":["Keep namespace URIs as named constants in a shared file.","Validate migration/config tables for null entries before emitting attributes."],"tags":["xaml","wpf","null-argument","attribute","constructor","namespace"],"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"}