{"record":{"id":"47c6fa434043c0f2","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderunsupportedrootnamespaceuri","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderUnsupportedRootNamespaceUri","messagePattern":"SR\\.XpsValidatingLoaderUnsupportedRootNamespaceUri","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":214,"sourceCode":"\n            public override string GetAttribute( int i ) \n            {\n                string attr = Reader.GetAttribute( i );\n                CheckUri(attr);\n                return attr;\n            }\n\n            public override bool Read() \n            {\n                bool result;\n                _node++;\n                result = Reader.Read();\n\n                if ( (Reader.NodeType == XmlNodeType.Element) && !_rootXMLNSChecked )\n                {\n                    if (!_schema.IsValidRootNamespaceUri(Reader.NamespaceURI))\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedRootNamespaceUri);\n                    }\n                    _rootXMLNSChecked = true;\n                }\n\n                return result;\n            }\n\n            private XpsValidatingLoader _loader;\n            private XpsSchema _schema;\n            private Uri _packageUri;\n            private Uri _baseUri;\n            private string _lastAttr;\n            private int _node;\n            private bool _rootXMLNSChecked;\n        }\n    }\n\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L196-L232","documentation":"The first XML element read from an XPS part must belong to a namespace recognized by the part's schema (e.g. http://schemas.microsoft.com/xps/2005/06). If IsValidRootNamespaceUri returns false for the root element's NamespaceURI, Read() throws FileFormatException because the part content is not valid XPS markup of the declared MIME type.","triggerScenarios":"Loading an XPS part whose root element is in a foreign namespace — e.g. root <html>, an XHTML FixedPage, a ResourceDictionary in the wrong namespace, or a missing/typo'd xmlns — encountered by XpsSchemaValidator.Read() when NodeType==Element and the root namespace hasn't been checked yet.","commonSituations":"Hand-authored FixedPage markup missing the xmlns declaration; parts renamed to .fpage/.fdseq without changing content; third-party XPS generators emitting their own namespaces; version-mismatched markup (e.g. older 2005/06 vs 2007/07 schema URLs mixed up).","solutions":["Set the root element's xmlns to the correct XPS schema namespace for the part type (e.g. http://schemas.microsoft.com/xps/2005/06 for FixedPage).","Confirm the part's Content Type matches its actual markup (a FixedDocumentSequence part must contain FixedDocumentSequence markup).","Regenerate the part from a conformant XPS producer rather than hand-editing.","Inspect the root element with a plain XmlReader before loading to verify NamespaceURI."],"exampleFix":"// before\n<Canvas xmlns=\"http://schemas.example.com/mycanvas\">...</Canvas>\n// after\n<FixedPage xmlns=\"http://schemas.microsoft.com/xps/2005/06\">...</FixedPage>","handlingStrategy":"validation","validationCode":"static readonly string[] XpsNamespaces = { \"http://schemas.microsoft.com/xps/2005/06\", \"http://schemas.microsoft.com/xps/2005/06/resourcedictionary-key\" };\nusing var xr = XmlReader.Create(part.GetStream());\nxr.MoveToContent();\nif (xr.NodeType == XmlNodeType.Element && !XpsNamespaces.Contains(xr.NamespaceURI))\n    throw new InvalidDataException($\"Root namespace {xr.NamespaceURI} is not a valid XPS root namespace\");","typeGuard":"static bool HasValidXpsRootNamespace(XmlReader r) =>\n    r.NodeType == XmlNodeType.Element &&\n    r.NamespaceURI == \"http://schemas.microsoft.com/xps/2005/06\";","tryCatchPattern":"try { loader.Load(stream); }\ncatch (FileFormatException ex) { // root namespace rejected: log part URI + ContentType for diagnosis\n    Console.WriteLine($\"Part is not conformant XPS markup: {ex.Message}\"); throw; }","preventionTips":["Always declare the correct XPS xmlns on the root element of FixedPage/FixedDocument/FixedDocumentSequence parts.","Keep part Content Type and markup namespace in sync.","Avoid re-purposing non-XPS XML as XPS parts.","Validate generated markup with the XPS loader in CI."],"tags":["xps","xml","namespace","schema"],"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"}