{"record":{"id":"427cb62578fd9fa7","repo":"JeffreySu/WeiXinMPSDK","slug":"strategy-gettype-name-getcapabilities","errorCode":null,"errorMessage":"缓存策略 {strategy.GetType().Name} 不支持枚举，请先检查 GetCapabilities()。","messagePattern":"缓存策略 (.+?) 不支持枚举，请先检查 GetCapabilities\\(\\)。","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin/Senparc.Weixin/Cache/ContainerCacheCapabilities.cs","lineNumber":108,"sourceCode":"            this IContainerCacheStrategy strategy,\n            int offset,\n            int pageSize,\n            CancellationToken cancellationToken = default)\n            where TBag : IBaseContainerBag\n        {\n            if (offset < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(offset));\n            }\n\n            if (pageSize <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(pageSize));\n            }\n\n            if (!strategy.Supports(ContainerCacheCapabilities.AsyncEnumeration))\n            {\n                throw new NotSupportedException($\"缓存策略 {strategy.GetType().Name} 不支持枚举，请先检查 GetCapabilities()。\");\n            }\n\n            cancellationToken.ThrowIfCancellationRequested();\n            var all = await strategy.GetAllAsync<TBag>().ConfigureAwait(false);\n            cancellationToken.ThrowIfCancellationRequested();\n            var page = all.OrderBy(item => item.Key, StringComparer.Ordinal)\n                .Skip(offset)\n                .Take(pageSize)\n                .ToList();\n            return new ContainerCachePage<TBag>(page, offset, all.Count);\n        }\n    }\n}\n","sourceCodeStart":90,"sourceCodeEnd":122,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin/Senparc.Weixin/Cache/ContainerCacheCapabilities.cs#L90-L122","documentation":"GetPageAsync requires the cache strategy to support AsyncEnumeration. Before paginating, it checks strategy.GetCapabilities() and throws NotSupportedException if the ContainerCacheCapabilities.AsyncEnumeration flag is absent. This guards against strategies (e.g. some distributed caches) that cannot enumerate all keys.","triggerScenarios":"Calling ContainerCacheExtensions/GetPageAsync (or a paged helper) with a cache strategy whose GetCapabilities() does not include ContainerCacheCapabilities.AsyncEnumeration.","commonSituations":"Switching cache containers (e.g. from local MemoryCache to a Redis/distributed strategy) at runtime or via config without verifying the new strategy supports enumeration; using a custom ICacheStrategyImplementation that omitted the AsyncEnumeration capability.","solutions":["Check the active strategy's capabilities before paging: strategy.GetCapabilities().HasFlag(ContainerCacheCapabilities.AsyncEnumeration).","Switch to a cache strategy that supports AsyncEnumeration (e.g. local/container cache or a Redis strategy configured with keyspace enumeration).","If the strategy truly cannot enumerate, replace pagination with direct key-based lookups (GetAsync with known keys) or maintain your own index of keys.","Register a custom strategy implementation that implements GetAllAsync and declares the AsyncEnumeration capability."],"exampleFix":"// before\nvar page = await cache.GetPageAsync<MyBag>(strategy, 1, 20);\n// after\nif (strategy.GetCapabilities().HasFlag(ContainerCacheCapabilities.AsyncEnumeration))\n{\n    var page = await cache.GetPageAsync<MyBag>(strategy, 1, 20);\n}\nelse\n{\n    var item = await strategy.GetAsync<MyBag>(key); // key-based access instead\n}","handlingStrategy":"validation","validationCode":"var caps = strategy.GetCapabilities();\nif (!caps.HasFlag(ContainerCacheCapabilities.AsyncEnumeration))\n    throw new InvalidOperationException($\"{strategy.GetType().Name} cannot enumerate; use key-based GetAsync instead.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var page = await GetPageAsync<T>(strategy, pageIndex, pageSize, ct);\n}\ncatch (NotSupportedException ex)\n{\n    Log(ex.Message);\n    // fall back to key-based access\n}","preventionTips":["Check GetCapabilities() of any custom or swapped cache strategy before using paged APIs.","Document which cache backends your app requires (enumeration-capable) in deployment config.","Add an integration test that calls paged APIs against the production cache strategy."],"tags":["cache","not-supported","pagination","senparc-weixin"],"backgroundTag":"unsupported-operation","analyzedSha":"be573f6f94bdbf718dd5f6cdecb137fbc7ff651e","analyzedAt":"2026-09-12T10:01:50.733Z","contentChangedAt":"2026-09-12T10:01:50.733Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}