{"record":{"id":"8939843eced0a50e","repo":"dotnet/wpf","slug":"e-fail","errorCode":"E_FAIL","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":54,"sourceCode":"\n        /// <summary>\n        /// Initialzes the session for this filter.\n        /// </summary>\n        /// <param name=\"grfFlags\">usage flags</param>\n        /// <param name=\"cAttributes\">number of elements in aAttributes array</param>\n        /// <param name=\"aAttributes\">array of FULLPROPSPEC structs to restrict responses</param>\n        /// <returns>\n        /// IFILTER_FLAGS_NONE to indicate that the caller should not use the IPropertySetStorage\n        /// and IPropertyStorage interfaces to locate additional properties.\n        /// </returns>\n        IFILTER_FLAGS IFilter.Init(\n            [In] IFILTER_INIT grfFlags,\n            [In] uint cAttributes,\n            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] FULLPROPSPEC[] aAttributes)\n        {\n            if (_filter == null)\n            {\n                throw new COMException(SR.FileToFilterNotLoaded,\n                    (int)NativeMethods.E_FAIL);\n            }\n\n            if (cAttributes > 0 && aAttributes == null)\n            {\n                // Attributes count and array do not match.\n                throw new COMException(SR.FilterInitInvalidAttributes,\n                    (int)NativeMethods.E_INVALIDARG);\n            }\n\n            return _filter.Init(grfFlags, cAttributes, aAttributes);\n        }\n\n        /// <summary>\n        /// Returns description of the next chunk.\n        /// </summary>\n        /// <returns>Chunk descriptor</returns>\n        STAT_CHUNK IFilter.GetChunk()","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs#L36-L72","documentation":"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.","triggerScenarios":"Calling IFilter.Init on an XpsFilter instance without previously calling IPersistFile.Load with a valid package file path, or after Load failed without checking.","commonSituations":"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.","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"],"exampleFix":"// before\nvar filter = new XpsFilter();\nfilter.Init(IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS, 0, null);\n// after\nvar filter = new XpsFilter();\n((IPersistFile)filter).Load(path, STGM.READ);\nfilter.Init(IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS, 0, null);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ((IPersistFile)filter).Load(path, STGM.READ); }\ncatch (COMException) { /* abort indexing for this file */ }\ntry { filter.Init(flags, 0, null); }\ncatch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004005)) { /* re-load or skip */ }","preventionTips":["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"],"tags":["wpf","xps","ifilter","com","state"],"backgroundTag":"invalid-state-transition","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"}