dotnet/wpf · error · COMException
E_FAIL
E_FAIL
Error message
File to filter is not loaded.
What it means
XpsFilter.Init implements IFilter.Init and requires that a file first be loaded via IPersistFile.Load, which sets _filter. If no file was loaded, _filter is null and Init throws COMException with E_FAIL.
Solutions
- Call IPersistFile.Load(path) on the XpsFilter instance before calling IFilter.Init
- Check that the file passed to Load is a valid XPS or encrypted OPC package
- Handle the COMException (E_FAIL) and re-load the filter before retrying
Example fix
// before var filter = new XpsFilter(); filter.Init(IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS, 0, null); // after var filter = new XpsFilter(); ((IPersistFile)filter).Load(path, STGM.READ); filter.Init(IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS, 0, null);
Defensive patterns
Strategy: try-catch
Try / catch
try { ((IPersistFile)filter).Load(path, STGM.READ); }
catch (COMException) { /* abort indexing for this file */ }
try { filter.Init(flags, 0, null); }
catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004005)) { /* re-load or skip */ } Prevention
- Always initialize filters via the documented Load -> Init -> GetChunk sequence
- Validate the file is a loadable package before creating the filter
- Wrap IFilter usage in a helper that enforces call order
When it happens
Trigger: Calling IFilter.Init on an XpsFilter instance without previously calling IPersistFile.Load with a valid package file path, or after Load failed without checking.
Common situations: Indexing/preview infrastructure instantiating XpsFilter directly and calling IFilter methods out of order, or Load failing because the path is not a valid XPS/OPC package.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- FILTER_E_ACCESS
- E_INVALIDARG
- E_NOTIMPL
- Buffer address passed to GetText cannot be NULL.
- PrintingCanceledException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8939843eced0a50e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs:54
/// <summary>
/// Initialzes the session for this filter.
/// </summary>
/// <param name="grfFlags">usage flags</param>
/// <param name="cAttributes">number of elements in aAttributes array</param>
/// <param name="aAttributes">array of FULLPROPSPEC structs to restrict responses</param>
/// <returns>
/// IFILTER_FLAGS_NONE to indicate that the caller should not use the IPropertySetStorage
/// and IPropertyStorage interfaces to locate additional properties.
/// </returns>
IFILTER_FLAGS IFilter.Init(
[In] IFILTER_INIT grfFlags,
[In] uint cAttributes,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] FULLPROPSPEC[] aAttributes)
{
if (_filter == null)
{
throw new COMException(SR.FileToFilterNotLoaded,
(int)NativeMethods.E_FAIL);
}
if (cAttributes > 0 && aAttributes == null)
{
// Attributes count and array do not match.
throw new COMException(SR.FilterInitInvalidAttributes,
(int)NativeMethods.E_INVALIDARG);
}
return _filter.Init(grfFlags, cAttributes, aAttributes);
}
/// <summary>
/// Returns description of the next chunk.
/// </summary>
/// <returns>Chunk descriptor</returns>
STAT_CHUNK IFilter.GetChunk()View on GitHub (pinned to 81131a70a4)