{"record":{"id":"a447481a58ed39aa","repo":"dotnet/wpf","slug":"throw-new-argumentnullexception-nameof-prefix","errorCode":null,"errorMessage":"throw new ArgumentNullException( nameof(prefix));","messagePattern":"throw new ArgumentNullException\\( nameof\\(prefix\\)\\);","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs","lineNumber":337,"sourceCode":"        /// dynamic property). Any attempt to modify the dictionary after this function is called will result in\n        /// a InvalidOperationException being thrown.\n        /// </summary>\n        public void Seal()\n        {\n            _sealed = true;\n        }\n#endif\n\n        /// <summary>\n        /// Looks up the namespace corresponding to an XML namespace prefix\n        /// </summary>\n        /// <param name=\"prefix\">The XML namespace prefix to look up</param>\n        /// <returns>The namespace corresponding to the given prefix if it exists, null otherwise</returns>\n        public string LookupNamespace(string prefix)\n        {\n            if (prefix == null)\n            {\n                throw new ArgumentNullException( nameof(prefix)); \n            }\n            \n            if (_lastDecl >0)\n            {\n                for (int thisDecl = _lastDecl-1; thisDecl >= 0; thisDecl--)\n                {\n                    if ((_nsDeclarations[thisDecl].Prefix == prefix) && \n                        !string.IsNullOrEmpty(_nsDeclarations[thisDecl].Uri))\n                    {\n                        return _nsDeclarations[thisDecl].Uri;\n                    }\n                }\n            }\n            return null;\n        }\n\n#if !PBTCOMPILER\n        /// <summary>","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XmlnsDictionary.cs#L319-L355","documentation":"This is a null-argument guard: XmlnsDictionary.LookupNamespace throws ArgumentNullException when the prefix parameter is null. Only non-null string prefixes (empty string allowed for the default namespace) may be looked up.","triggerScenarios":"Calling xmlnsDictionary.LookupNamespace(null), typically forwarding an uninitialized prefix variable or a null result from an earlier lookup.","commonSituations":"Custom IXmlNamespaceResolver implementations delegating to XmlnsDictionary with a null prefix read from parsed markup; prefix fields not initialized before lookup.","solutions":["Guard with a null check before calling LookupNamespace and return early for null prefixes","Treat an empty string as 'no prefix' (default namespace) rather than passing null"],"exampleFix":"// before\nvar ns = dictionary.LookupNamespace(prefix);\n\n// after\nvar ns = prefix != null ? dictionary.LookupNamespace(prefix) : null;","handlingStrategy":"type-guard","validationCode":"var ns = prefix == null ? null : dictionary.LookupNamespace(prefix);","typeGuard":"bool HasPrefix(string prefix) => !string.IsNullOrEmpty(prefix);","tryCatchPattern":"try { ns = dictionary.LookupNamespace(prefix); }\ncatch (ArgumentNullException) { ns = null; }","preventionTips":["Null-check prefix variables before resolution","Use string.Empty for the default (no-prefix) namespace instead of null","Initialize prefix fields so they never default to null"],"tags":["wpf","xaml","null-reference"],"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"}