{"record":{"id":"4d1109a423d8bb56","repo":"dotnet/wpf","slug":"bindregion-is-not-implemented-packagefilter","errorCode":null,"errorMessage":"BindRegion is not implemented.","messagePattern":"BindRegion is not implemented\\.","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs","lineNumber":258,"sourceCode":"            {\n                throw new COMException(SR.FilterGetValueNotSupported,\n                    (int)FilterErrorCode.FILTER_E_NO_VALUES);\n            }\n\n            return _currentFilter.GetValue();\n        }\n\n        /// <summary>\n        /// BindRegion\n        /// </summary>\n        /// <param name=\"origPos\"></param>\n        /// <param name=\"riid\"></param>\n        /// <remarks>\n        /// The MSDN specification requires this function to return E_NOTIMPL for the time being.\n        /// </remarks>\n        public IntPtr BindRegion(FILTERREGION origPos, ref Guid riid)\n        {\n            throw new NotImplementedException(SR.FilterBindRegionNotImplemented);\n        }\n\n        #endregion IFilter methods\n\n        #region Private methods\n        /// <summary>\n        /// Find a filter object given its CLSID.\n        /// </summary>\n        /// <remarks>\n        /// <para>\n        /// If the clsid is not a proper IFilter clsid, this function will return null.\n        /// The caller will then ignore the current part and attempt to filter the next part.\n        /// </para>\n        /// <para>\n        /// Non-fatal exceptions from external filters, identified for all practical purposes\n        /// with InvalidCastException, COMException and IOException, are `swallowed by this method.\n        /// </para>\n        /// </remarks>","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/IO/Packaging/PackageFilter.cs#L240-L276","documentation":"PackageFilter.BindRegion wraps a COM IFilter for a package part. The MSDN IFilter specification requires BindRegion to return E_NOTIMPL, so this managed adapter deliberately throws NotImplementedException(SR.FilterBindRegionNotImplemented). It is not a bug; the operation is permanently unimplemented for every caller.","triggerScenarios":"Calling PackageFilter.BindRegion(FILTERREGION, ref Guid) directly, or routing through the IFilter interface of PackageFilter (e.g. when a Windows Search / indexing pipeline attempts to bind a region of the filtered document).","commonSituations":"Code that implements or consumes IFilter plumbing (custom search/indexing over XPS/OPC packages) calls BindRegion to map text offsets to monikers; any such call against PackageFilter fails by design on all .NET/WPF versions.","solutions":["Do not call BindRegion on PackageFilter; restructure code so positions are consumed via IFilter::GetChunk/GetText instead of region binding.","Catch NotImplementedException and treat the result as E_NOTIMPL, exactly as a native IFilter consumer must.","If region binding is required, use a native IFilter implementation rather than PackageFilter."],"exampleFix":"// before\nvar riid = Guid.NewGuid();\nvar ptr = filter.BindRegion(origPos, ref riid);\n// after\n// BindRegion is specified as E_NOTIMPL; avoid the call\n// consume chunks/text instead:\n// while (filter.GetChunk(...) == ... ) { filter.GetText(...); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { filter.BindRegion(origPos, ref riid); }\ncatch (NotImplementedException)\n{\n    // E_NOTIMPL per IFilter spec — skip region binding, use GetChunk/GetText\n}","preventionTips":["Never call BindRegion on PackageFilter; the spec mandates E_NOTIMPL.","Design indexing consumers around chunks and text retrieval, not region binding.","Treat BindRegion as unsupported in any IFilter abstraction layer."],"tags":["ifilter","packaging","not-implemented","indexing"],"backgroundTag":"method-not-implemented","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"}