{"record":{"id":"e9366c8089e0cbf8","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderunsupportedmimetype-e9366c","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderUnsupportedMimeType","messagePattern":"SR\\.XpsValidatingLoaderUnsupportedMimeType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs","lineNumber":167,"sourceCode":"                            {\n                                if (!validResources.ContainsKey(absTargetUri))\n                                {\n                                    validResources.Add(absTargetUri, false);\n                                }\n                            }\n                        }\n                    }\n\n                    XpsSchemaValidator xpsSchemaValidator = new XpsSchemaValidator(this, schema, mimeType,\n                                                                                    stream, packageUri, partUri);\n                    _validResources.Push(validResources);\n                    if (rootElement != null)\n                    {\n                        xpsSchemaValidator.XmlReader.MoveToContent();\n\n                        if (!rootElement.Equals(xpsSchemaValidator.XmlReader.Name))\n                        {\n                            throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedMimeType);\n                        }\n\n                        while (xpsSchemaValidator.XmlReader.Read())\n                            ;\n                    }\n                    else\n                    {\n                        obj = XamlReader.Load(xpsSchemaValidator.XmlReader,\n                                    pc,\n                                    XamlParseMode.Synchronous, true, safeTypes);\n                    }\n                    _validResources.Pop();\n                }\n                finally\n                {\n                    XpsLoadingContext.ActivePackageUri = previousPackageUri;\n                }\n            }","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs#L149-L185","documentation":"XPSS0ValidatingLoader.Load throws FileFormatException (SR.XpsValidatingLoaderUnsupportedMimeType) when validating an XPS part in strict document mode: the root element name in the markup does not equal the root element expected for the part's declared MIME type. The content contradicts its content type, so the loader refuses it.","triggerScenarios":"Loading a part inside an XPS package where the XML root element (xpsSchemaValidator.XmlReader.Name) does not match the rootElement string required by the schema for the part's ContentType (XPSS0ValidatingLoader.cs:167), e.g. a part declared as application/vnd.ms-package.xps-fixedpage whose root is not 'FixedPage'.","commonSituations":"A malformed or hand-edited XPS file where a FixedDocument or ResourceDictionary part contains FixedPage markup or vice versa; wrong MIME type entry in [Content_Types].xml; a renamed root element; tooling that wrote a part with an incorrect content-type mapping.","solutions":["Fix the part's markup so its root element matches the declared MIME type's schema.","Correct the part's ContentType in [Content_Types].xml or its relationships to reflect the actual markup.","Regenerate the XPS package with a compliant producer instead of hand-editing parts.","Validate the package with XPS tooling before loading."],"exampleFix":"// before: part declared xps-fixeddocument but contains FixedPage markup\n<FixedPage xmlns=\"...\">...</FixedPage>\n\n// after: root matches declared content type\n<FixedDocument xmlns=\"...\">...</FixedDocument>","handlingStrategy":"validation","validationCode":"// peek the first element name and compare to the expected root for the content type\nusing var reader = XmlReader.Create(stream, XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });\nreader.MoveToContent();\nbool rootMatches = reader.Name == \"FixedPage\"; // expected root for the declared MIME type","typeGuard":"static bool HasExpectedRoot(Stream s, string expectedRoot)\n{\n    using var r = XmlReader.Create(s, new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore });\n    r.MoveToContent();\n    return r.Name == expectedRoot;\n}","tryCatchPattern":"try\n{\n    obj = loader.Load(stream, parentUri, pc, mimeType);\n}\ncatch (FileFormatException ex)\n{\n    // content type / root mismatch: reject or repair the package part\n}","preventionTips":["Keep [Content_Types].xml entries consistent with actual part markup","Never hand-edit XPS part contents; regenerate with a compliant producer","Verify root element names against the XPS schema per part type","Run XPS validation tooling on generated packages"],"tags":["xps","mime-type","validation","file-format","xaml"],"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-22T01:17:13.364Z"}