dotnet/wpf · error · COMException
FILTER_E_UNKNOWNFORMAT
FILTER_E_UNKNOWNFORMAT
Error message
File to filter is not loaded.
What it means
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.
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
Example fix
// before
filter.Load(path, (int)STGM_FLAGS.READ); // may hit non-XPS data
// after
try { filter.Load(path, (int)STGM_FLAGS.READ); }
catch (COMException ex) when (ex.HResult == unchecked((int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT))
{
// log and skip: not an XPS package
} Defensive patterns
Strategy: validation
Validate before calling
using (var fs = File.OpenRead(path))
using (var pk = new System.IO.Packaging.ZipPackage(fs)) { /* throws FileFormatException if not OPC */ } Try / catch
try { filter.Load(path, (int)STGM_FLAGS.READ); }
catch (COMException ex) when (ex.HResult == unchecked((int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT))
{ /* skip: not an XPS package */ } Prevention
- Verify files are real XPS packages before indexing
- Enforce correct extensions at ingest; validate magic bytes/OPC structure
- Quarantine files that fail format validation
When it happens
Trigger: 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.
Common situations: Indexers picking up files saved with wrong extensions; interrupted uploads stored as .xps; hand-crafted ZIPs missing [Content_Types].xml.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- ' ' cannot contain the path delimiter: ' '.
- ' ' cannot start with the reserved character range…
- ' ' ID is not a valid XSD ID.
- 0x80004002
- 0x80040200
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2054341a7b4840e4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs:427
{
// Open the encrypted package.
_encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream);
_filter = new EncryptedPackageFilter(_encryptedPackage);
}
else
{
// Open the package.
_package = Package.Open(_packageStream);
_filter = new PackageFilter(_package);
}
}
catch (IOException ex)
{
throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS);
}
catch (FileFormatException ex)
{
throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);
}
finally
{
// failure?
if (_filter == null)
{
// clean up
ReleaseResources();
}
}
_xpsFileName = pszFileName;
}
/// <summary>
/// Saves a copy of the object into the specified file.
/// </summary>
/// <param name="pszFileName">View on GitHub (pinned to 81131a70a4)