{"record":{"id":"25858f14cc249ea8","repo":"JeffreySu/WeiXinMPSDK","slug":"0","errorCode":null,"errorMessage":"注册委托容量必须大于 0。","messagePattern":"注册委托容量必须大于 0。","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin/Senparc.Weixin/Containers/BaseContainer.cs","lineNumber":221,"sourceCode":"\n        /// <summary>当前保留的自动重注册委托数量。</summary>\n        public static int RegistrationCallbackCount => RegisterFuncCollection.Count;\n\n        /// <summary>自动重注册委托容量上限。默认 10000。</summary>\n        public static int MaximumRegistrationCallbackCount\n        {\n            get\n            {\n                lock (RegistrationCallbackSyncRoot)\n                {\n                    return _maximumRegistrationCallbackCount;\n                }\n            }\n            set\n            {\n                if (value <= 0)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), \"注册委托容量必须大于 0。\");\n                }\n\n                lock (RegistrationCallbackSyncRoot)\n                {\n                    if (value < RegisterFuncCollection.Count)\n                    {\n                        throw new InvalidOperationException($\"当前已有 {RegisterFuncCollection.Count} 个注册委托，不能把容量降低到 {value}。\");\n                    }\n\n                    _maximumRegistrationCallbackCount = value;\n                }\n            }\n        }\n\n        /// <summary>\n        /// 为 SDK 内部注册自动刷新委托，同时执行容量检查。\n        /// 保留 <see cref=\"RegisterFuncCollection\"/> 的历史类型，以兼容外部派生容器。\n        /// </summary>","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin/Senparc.Weixin/Containers/BaseContainer.cs#L203-L239","documentation":"BaseContainer exposes MaximumRegistrationCallbackCount, the cap on how many registration callbacks (one per container bag/account) can be stored. The setter validates that the new value is > 0 and throws ArgumentOutOfRangeException for zero or negative values.","triggerScenarios":"Setting MaximumRegistrationCallbackCount (static property on a BaseContainer-derived container) to 0 or a negative number, typically from config parsing that yields 0 as a default when the config key is missing.","commonSituations":"Reading the limit from appsettings with int.Parse/TryParse defaulting to 0; misconfigured environment variables; code assuming a boolean-like 'disable limit' semantic by passing 0.","solutions":["Set MaximumRegistrationCallbackCount to a positive integer sized to your account count (e.g. 100+).","If the value comes from config, guard: only assign when the parsed value > 0; otherwise keep the library default.","Use int.TryParse with an explicit positive check instead of defaulting to 0 on parse failure.","Do not try to 'disable' the cap with 0 — the property only accepts positive values."],"exampleFix":"// before\nvar limit = int.Parse(config[\"MaxRegistrations\"]); // 0 when key missing\nMyContainer.MaximumRegistrationCallbackCount = limit; // throws\n// after\nif (int.TryParse(config[\"MaxRegistrations\"], out var limit) && limit > 0)\n{\n    MyContainer.MaximumRegistrationCallbackCount = limit;\n} // else keep library default","handlingStrategy":"validation","validationCode":"if (value <= 0)\n    throw new InvalidOperationException(\"MaximumRegistrationCallbackCount must be positive.\");\nMyContainer.MaximumRegistrationCallbackCount = value;","typeGuard":null,"tryCatchPattern":"try\n{\n    MyContainer.MaximumRegistrationCallbackCount = parsedLimit;\n}\ncatch (ArgumentOutOfRangeException ex)\n{\n    Log($\"Invalid limit {parsedLimit}: {ex.Message}; keeping default.\");\n}","preventionTips":["Never assign limits straight from parsed config without a >0 check.","Don't use 0 to mean 'unlimited' — the setter rejects it.","Centralize all container-limit assignments in startup code with validation.","Use int.TryParse with explicit bounds instead of default-on-failure."],"tags":["config","container","argument-out-of-range","senparc-weixin"],"backgroundTag":"value-out-of-range","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"}