{"record":{"id":"ed57c3f87095af47","repo":"JeffreySu/WeiXinMPSDK","slug":"requestmethod","errorCode":null,"errorMessage":"requestMethod","messagePattern":"requestMethod","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs","lineNumber":242,"sourceCode":"                case ApiRequestMethod.DELETE:\n                    WeixinTrace.Log(url);\n                    break;\n                case ApiRequestMethod.POST:\n                case ApiRequestMethod.PUT:\n                case ApiRequestMethod.PATCH:\n                    if (checkDataNotNull)\n                    {\n                        _ = data ?? throw new ArgumentNullException($\"{nameof(data)} 不能为 null！\");\n                    }\n\n                    string jsonString = data != null\n                        ? data.ToJson(false, RequestJsonSerializerSettings)\n                        : \"\";\n                    WeixinTrace.SendApiPostDataLog(url, jsonString);\n                    request.Content = new StringContent(jsonString, Encoding.UTF8, mediaType: \"application/json\");\n                    break;\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(requestMethod));\n            }\n\n            using var timeoutCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);\n            if (timeOut != Timeout.Infinite)\n            {\n                timeoutCancellationTokenSource.CancelAfter(timeOut);\n            }\n\n            return await _client.Value.SendAsync(request, completionOption, timeoutCancellationTokenSource.Token).ConfigureAwait(false);\n        }\n\n        private static HttpMethod GetHttpMethod(ApiRequestMethod requestMethod)\n        {\n            switch (requestMethod)\n            {\n                case ApiRequestMethod.GET:\n                    return HttpMethod.Get;\n                case ApiRequestMethod.POST:","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs#L224-L260","documentation":"ArgumentOutOfRangeException for the requestMethod parameter in GetHttpResponseMessageAsync's default switch branch: the supplied ApiRequestMethod value is not one of the handled GET/POST/PUT/PATCH cases.","triggerScenarios":"Casting an arbitrary int to ApiRequestMethod (e.g. (ApiRequestMethod)7) or passing an enum member added in a newer library version while running an older build of TenPayApiRequest.","commonSituations":"Persisting the enum value to config/database and reading back an out-of-range number; assembly version mismatch between projects in the solution.","solutions":["Only pass valid ApiRequestMethod members (GET, POST, PUT, PATCH)","If loading from config, validate/parse the value against the enum before use","Align library versions so enum definitions match across projects"],"exampleFix":"// before\nvar method = (ApiRequestMethod)someInt;\nawait request.GetAsync(url, requestMethod: method);\n// after\nvar method = Enum.IsDefined(typeof(ApiRequestMethod), someInt) ? (ApiRequestMethod)someInt : ApiRequestMethod.POST;\nawait request.GetAsync(url, requestMethod: method);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ApiRequestMethod), requestMethod))\n    throw new InvalidDataException($\"未知的 ApiRequestMethod: {requestMethod}\");","typeGuard":null,"tryCatchPattern":"try { await request.GetAsync(url, requestMethod: method); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"requestMethod\") { log.Error(\"非法 requestMethod\", ex); throw; }","preventionTips":["Only assign ApiRequestMethod via enum members, never unchecked int casts","When persisting method to config/DB, parse with Enum.TryParse and reject unknown values","Keep Senparc.Weixin.TenPay versions aligned across all projects"],"tags":["wechat-pay","invalid-enum-value","http-method"],"backgroundTag":"invalid-enum-value","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"}