{"record":{"id":"2054341a7b4840e4","repo":"dotnet/wpf","slug":"filter-e-unknownformat","errorCode":"FILTER_E_UNKNOWNFORMAT","errorMessage":"File to filter is not loaded.","messagePattern":"File to filter is not loaded\\.","errorType":"exception","errorClass":"COMException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs","lineNumber":427,"sourceCode":"                {\n                    // Open the encrypted package.\n                    _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream);\n                    _filter = new EncryptedPackageFilter(_encryptedPackage);\n                }\n                else\n                {\n                    // Open the package.\n                    _package = Package.Open(_packageStream);\n                    _filter = new PackageFilter(_package);\n                }\n            }\n            catch (IOException ex)\n            {\n                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS);\n            }\n            catch (FileFormatException ex)\n            {\n                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);\n            }\n            finally\n            {\n                // failure?\n                if (_filter == null)\n                {\n                    // clean up\n                    ReleaseResources();\n                }\n}\n\n            _xpsFileName = pszFileName;\n        }\n\n        /// <summary>\n        /// Saves a copy of the object into the specified file.\n        /// </summary>\n        /// <param name=\"pszFileName\">","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs#L409-L445","documentation":"When the bytes are readable but not a valid XPS/OPC package, Package.Open throws FileFormatException, which Load translates into a COMException with hresult FILTER_E_UNKNOWNFORMAT. \"File to filter is not loaded.\" again reflects that _filter stayed null in the finally block.","triggerScenarios":"Load called on a file whose stream is not an OPC/XPS container — wrong extension, ODF/DOCX/PDF renamed to .xps, or a corrupt/partial download.","commonSituations":"Indexers picking up files saved with wrong extensions; interrupted uploads stored as .xps; hand-crafted ZIPs missing [Content_Types].xml.","solutions":["Verify the file is a genuine XPS (OPC) package, e.g. opens in an XPS viewer","Fix file extension/source so the real format matches expectations","Regenerate or re-download a corrupt/partial file","Catch COMException with FILTER_E_UNKNOWNFORMAT and skip the file in indexing pipelines"],"exampleFix":"// before\nfilter.Load(path, (int)STGM_FLAGS.READ); // may hit non-XPS data\n// after\ntry { filter.Load(path, (int)STGM_FLAGS.READ); }\ncatch (COMException ex) when (ex.HResult == unchecked((int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT))\n{\n    // log and skip: not an XPS package\n}","handlingStrategy":"validation","validationCode":"using (var fs = File.OpenRead(path))\nusing (var pk = new System.IO.Packaging.ZipPackage(fs)) { /* throws FileFormatException if not OPC */ }","typeGuard":null,"tryCatchPattern":"try { filter.Load(path, (int)STGM_FLAGS.READ); }\ncatch (COMException ex) when (ex.HResult == unchecked((int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT))\n{ /* skip: not an XPS package */ }","preventionTips":["Verify files are real XPS packages before indexing","Enforce correct extensions at ingest; validate magic bytes/OPC structure","Quarantine files that fail format validation"],"tags":["format","com","wpf","packaging"],"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"}