{"record":{"id":"4458fec8c0b7ea67","repo":"dotnet/wpf","slug":"sr-parserfilterxmlreadernodefinitionprefixchangeallowed","errorCode":null,"errorMessage":"SR.ParserFilterXmlReaderNoDefinitionPrefixChangeAllowed","messagePattern":"SR\\.ParserFilterXmlReaderNoDefinitionPrefixChangeAllowed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/FilteredXmlReader.cs","lineNumber":341,"sourceCode":"        }\n    }\n\n    // This is called whenever a node is about to be returned to the user.  We\n    //  check to see if it's a \"xmlns\" node that re-defines the \"Definition\"\n    //  namespace.\n    private void CheckForNamespaceRedef()\n    {\n        // xmlns node example: < [...] xmlns:someprefix=\"http://schemas.microsoft.com/winfx/2006/xaml\" [...}/>\n        //  base.Name = \"xmlns:someprefix\"\n        //  base.LocalName = \"someprefix\"\n        //  base.Prefix = \"xmlns\"\n        //  base.Value =\"http://schemas.microsoft.com/winfx/2006/xaml\" = uidNamespace\n        \n        if( base.Prefix == \"xmlns\" &&         // Fixed via XML spec\n            base.LocalName != uidPrefix &&    // Hey, this prefix isn't the one we think it is.\n            base.Value == uidNamespace)\n        {\n            throw new InvalidOperationException(\n                SR.ParserFilterXmlReaderNoDefinitionPrefixChangeAllowed);\n        }\n    }\n\n        #endregion Private Methods\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n\n        #region Private Fields\n\n        // These are fixed, by definition of the Uid feature.\n        private const string uidLocalName = \"Uid\";\n        private const string uidNamespace = XamlReaderHelper.DefinitionNamespaceURI;\n        private const string defaultPrefix = \"def\";","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/FilteredXmlReader.cs#L323-L359","documentation":"FilteredXmlReader enforces that the reserved 'x' prefix (XAML language namespace, http://schemas.microsoft.com/winfx/2006/xaml) is not redefined. When it encounters an xmlns declaration that rebinds some prefix other than x:Uid's to the XAML language namespace (or otherwise conflicts with the reserved definition), CheckForNamespaceRedef throws InvalidOperationException.","triggerScenarios":"XAML input containing a namespace declaration such as xmlns:foo=\"http://schemas.microsoft.com/winfx/2006/xaml\" — any prefix other than the reserved one bound to the XAML language namespace while parsing.","commonSituations":"Hand-edited or tool-generated XAML that remaps the x namespace; copy-pasted markup with conflicting xmlns aliases; malicious or malformed XAML fed to localization (uid-filtered) parsing.","solutions":["Remove the xmlns declaration that rebinds a non-reserved prefix to the XAML language namespace","Use the reserved 'x:' prefix for XAML language features instead of redefining it","If you need an alias, alias to a different (non-XAML-language) namespace","Validate the XAML's xmlns declarations before passing it through FilteredXmlReader"],"exampleFix":"// before\n<Page xmlns:foo=\"http://schemas.microsoft.com/winfx/2006/xaml\" ...>\n// after\n<Page xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" ...>","handlingStrategy":"validation","validationCode":"foreach (var (prefix, ns) in collectedNamespaces) if (ns == \"http://schemas.microsoft.com/winfx/2006/xaml\" && prefix != \"x\") throw new XmlException($\"Prefix '{prefix}' may not redefine the XAML language namespace\");","typeGuard":"static bool IsLegalNamespaceDecl(string prefix, string ns) => ns != \"http://schemas.microsoft.com/winfx/2006/xaml\" || prefix == \"x\";","tryCatchPattern":"try { Parse(xamlStream); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"prefix\") || ex.Message.Contains(\"namespace\")) { throw new XamlParseException(\"Remove xmlns declarations that rebind the XAML language namespace to a non-x prefix\"); }","preventionTips":["Always use the reserved x: prefix for the XAML language namespace","Lint XAML files for xmlns declarations pointing at the xaml language URI with other prefixes","Sanitize tool-generated XAML before localization/uid filtering passes"],"tags":["xml","xaml","namespace"],"backgroundTag":"schema-validation-failed","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"}