{"record":{"id":"0aa18d9c96fd4bae","repo":"dotnet/wpf","slug":"filter-e-access","errorCode":"FILTER_E_ACCESS","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":76,"sourceCode":"            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()\n        {\n            if (_filter == null)\n            {\n                throw new COMException(SR.FileToFilterNotLoaded,\n                    (int)FilterErrorCode.FILTER_E_ACCESS);\n            }\n\n            try\n            {\n                return _filter.GetChunk();\n            }\n            catch (COMException ex)\n            {\n                // End-of-data?  If so, release the package.\n                if (ex.ErrorCode == (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS)\n                    ReleaseResources();\n\n                throw;\n            }\n        }\n\n        /// <summary>","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/XpsFilter.cs#L58-L94","documentation":"COMException from XpsFilter's IFilter.GetChunk: the inner filter object is null because Init/IPersistFile::Load was never completed, so there is no loaded file to enumerate chunks from; the error is returned as FILTER_E_ACCESS with the 'file not loaded' message.","triggerScenarios":"Calling IFilter.GetChunk() on an XpsFilter before IPersistFile.Load has populated the inner filter.","commonSituations":"Indexers iterating GetChunk/GetText loops on a filter instance whose Load step failed or was skipped.","solutions":["Call IPersistFile.Load before GetChunk","Verify Load succeeded and restart the chunk loop","Skip the file and log when the filter cannot be loaded"],"exampleFix":"// before\nvar chunk = ((IFilter)filter).GetChunk();\n// after\nif (!loaded) ((IPersistFile)filter).Load(path, STGM.READ);\nvar chunk = ((IFilter)filter).GetChunk();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { chunk = ((IFilter)filter).GetChunk(); }\ncatch (COMException ex) when ((uint)ex.ErrorCode == 0x80041200 || ex.ErrorCode == unchecked((int)0x80004005)) { /* skip file or reload */ }","preventionTips":["Enforce Load-then-use ordering in a wrapper class","Check Load success before starting chunk enumeration","Dispose or reset filter instances on failure"],"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"}