{"record":{"id":"7007d53bdf87dea1","repo":"dotnet/wpf","slug":"filter-e-end-of-chunks","errorCode":"FILTER_E_END_OF_CHUNKS","errorMessage":"Filter has no more chunks to return.","messagePattern":"Filter has no more chunks to return\\.","errorType":"error_code","errorClass":"COMException","httpStatus":null,"severity":"info","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/indexingfiltermarshaler.cs","lineNumber":273,"sourceCode":"        }\n\n        /// <summary>\n        /// GetChunk\n        /// </summary>\n        /// <returns>the next chunk</returns>\n        public STAT_CHUNK GetChunk()\n        {\n            // Get the managed chunk\n            ManagedChunk managedChunk = _implementation.GetChunk();\n\n            if (managedChunk == null)\n            {\n                // End of chunks.\n\n                if (ThrowOnEndOfChunks)\n                {\n                    // Throw exception.\n                    throw new COMException(SR.FilterEndOfChunks,\n                        (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS);\n                }\n\n                // Return STAT_CHUNK with idChunk as 0.\n\n                STAT_CHUNK chunk = new STAT_CHUNK\n                {\n                    idChunk = 0\n                };\n                return chunk;\n}\n\n            // Valid chunk. Return corresponding STAT_CHUNK.\n            return MarshalChunk(managedChunk);\n        }\n\n        /// <summary>\n        ///    GetText","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/indexingfiltermarshaler.cs#L255-L291","documentation":"The COM IFilter protocol signals normal end of enumeration with the HRESULT FILTER_E_END_OF_CHUNKS. WPF's IndexingFilterMarshaler surfaces this either as a COMException with that code (when ThrowOnEndOfChunks is true) or as an empty STAT_CHUNK sentinel. It is expected control flow, not a filter failure — the document's chunks are simply exhausted.","triggerScenarios":"A search host calls GetChunk after all chunks of the document have already been returned while ThrowOnEndOfChunks is true.","commonSituations":"Indexing loops that keep calling GetChunk without stopping on the end-of-chunks signal; test harnesses exercising WPF's IFilter wrapper for XPS documents; hosts ported from filters that return different termination sentinels.","solutions":["Treat this COMException as normal end-of-enumeration: catch it (matching the FILTER_E_END_OF_CHUNKS HResult) and break out of the loop","Set ThrowOnEndOfChunks = false so GetChunk returns an empty STAT_CHUNK sentinel instead of throwing","Structure the enumeration as a try/catch loop that terminates on this specific HResult rather than treating it as an error"],"exampleFix":"// before: unbounded loop crashes at end of document\nwhile (true)\n{\n    var chunk = filter.GetChunk();\n    Process(chunk);\n}\n\n// after: stop on the end-of-chunks signal\nwhile (true)\n{\n    try\n    {\n        var chunk = filter.GetChunk();\n        Process(chunk);\n    }\n    catch (COMException ex) when (ex.HResult == (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS)\n    {\n        break; // normal end of enumeration\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var chunk = filter.GetChunk();\n    Process(chunk);\n}\ncatch (COMException ex) when (ex.HResult == (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS)\n{\n    // expected end of enumeration — exit the loop, not an error\n}","preventionTips":["Treat end-of-chunks as normal termination and stop iterating on that specific HResult","Prefer ThrowOnEndOfChunks = false if your host handles an empty STAT_CHUNK sentinel more naturally","Never retry or log-as-failure on FILTER_E_END_OF_CHUNKS; it means the document is fully consumed"],"tags":["wpf","com-interop","ifilter","end-of-enumeration","windows-search"],"backgroundTag":"empty-result-set","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"}