{"record":{"id":"a6070116d18bb1e8","repo":"dotnet/wpf","slug":"sr-documentreferenceunsupportedmimetype","errorCode":null,"errorMessage":"SR.DocumentReferenceUnsupportedMimeType","messagePattern":"SR\\.DocumentReferenceUnsupportedMimeType","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs","lineNumber":294,"sourceCode":"                }\n\n                ParserContext pc = new ParserContext\n                {\n                    BaseUri = uriToLoad\n                };\n\n                if (BindUriHelper.IsXamlMimeType(mimeType))\n                {\n                    XpsValidatingLoader loader = new XpsValidatingLoader();\n                    idp = loader.Load(docStream, ((IUriContext)this).BaseUri, pc, mimeType) as FixedDocument;\n                }\n                else if (MS.Internal.MimeTypeMapper.BamlMime.AreTypeAndSubTypeEqual(mimeType))\n                {\n                    idp = XamlReader.LoadBaml(docStream, pc, null, true) as FixedDocument;\n                }\n                else\n                {\n                    throw new ApplicationException(SR.DocumentReferenceUnsupportedMimeType);\n                }\n                idp.DocumentReference = this;\n            }\n\n           return idp;\n        }\n        #endregion Private Methods\n\n        //--------------------------------------------------------------------\n        //\n        // Private Fields\n        //\n        //---------------------------------------------------------------------\n\n        #region Private Fields\n        private FixedDocument _doc;\n        private FixedDocument _docIdentity;     // used to cache the identity of the IDF so the IDF knows where it come from.\n        #endregion Private Fields","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/DocumentReference.cs#L276-L312","documentation":"_LoadDocument inspects the MIME type returned with the document stream. If it is neither XPS package MIME nor BAML MIME, it throws ApplicationException with SR.DocumentReferenceUnsupportedMimeType. The DocumentReference only knows how to load XPS (FixedDocument) and BAML content.","triggerScenarios":"DocumentReference.Source points at a resource whose server-reported Content-Type is neither application/vnd.ms-package.xps-fixeddocument nor the BAML MIME — e.g. HTML error pages, plain files, or a misconfigured server Content-Type mapping.","commonSituations":"Web server returning text/html for a missing file (soft 404) instead of the XPS file; IIS MIME map missing for .xps; pointing DocumentReference at a .fdseq or arbitrary file rather than a FixedDocument part.","solutions":["Point DocumentReference.Source at a real FixedDocument XPS part, not a container (.xps zip) or page sequence","Fix the server's MIME mapping so the XPS part is served with application/vnd.ms-package.xps-fixeddocument","Ensure the URI is not hitting an error/HTML page (verify by requesting the URL directly)","If loading a whole .xps package, open the package and reference the FixedDocument inside instead"],"exampleFix":"// before\ndocReference.Source = new Uri(\"pack://application:,,,/report.xps\"); // zip container, wrong MIME\n// after\ndocReference.Source = new Uri(\"pack://application:,,,/report.xps/Documents/1/FixedDocument.fdoc\");","handlingStrategy":"validation","validationCode":"if (uri.IsFile && !uri.LocalPath.EndsWith(\".fdoc\", StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException(\"Point DocumentReference at a FixedDocument .fdoc part\");","typeGuard":null,"tryCatchPattern":"try { var doc = docRef.GetDocument(); } catch (ApplicationException ex) { log.Error($\"Unsupported MIME for {docRef.Source}\", ex); }","preventionTips":["Reference the FixedDocument part inside the XPS, not the zip container","Confirm the server sends the correct Content-Type for .xps/.fdoc","Check the URL returns the document, not an HTML error page"],"tags":["wpf","xps","mime-type"],"backgroundTag":"incompatible-source-type","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"}