{"record":{"id":"ed483f86a5cdb51c","repo":"dotnet/wpf","slug":"argumentnullexception-nameof-newnamespace","errorCode":null,"errorMessage":"ArgumentNullException(nameof(newNamespace))","messagePattern":"ArgumentNullException\\(nameof\\(newNamespace\\)\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs","lineNumber":32,"sourceCode":"    ///    \"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":14,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/XmlnsCompatibleWithAttribute.cs#L14-L46","documentation":"The XmlnsCompatibleWithAttribute constructor throws ArgumentNullException when newNamespace is null. The new (compatible) namespace URI is required so the XAML infrastructure can map old namespace usage forward; null is rejected immediately.","triggerScenarios":"Executing new XmlnsCompatibleWithAttribute(\"http://old-namespace\", null) from assembly metadata or generated code.","commonSituations":"Migration tooling that emits compatibility attributes but fails to supply the target namespace; config/translation tables missing the new-namespace entry.","solutions":["Pass the full new namespace URI string.","Validate the source value for null before constructing the attribute.","Use shared namespace constants to keep old/new URIs consistent and non-null.","Catch ArgumentNullException when consuming untrusted metadata."],"exampleFix":"// before\nvar attr = new XmlnsCompatibleWithAttribute(oldNs, GetNewNs()); // null\n// after\nvar newNs = GetNewNs() ?? \"http://schemas.example.com/2010/xaml\";\nvar attr = new XmlnsCompatibleWithAttribute(oldNs, newNs);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(newNamespace)) throw new ArgumentException(\"newNamespace 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 generated attribute inputs for null before construction."],"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"}