{"record":{"id":"0803374dfd29911f","repo":"JeffreySu/WeiXinMPSDK","slug":"certtype","errorCode":null,"errorMessage":"certType","messagePattern":"certType","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayHttpClient/TenPaySignerFactory.cs","lineNumber":29,"sourceCode":"    /// </summary>\n    public static class TenPayCertFactory\n    {\n        /// <summary>\n        /// 获取签名对象\n        /// </summary>\n        /// <param name=\"certType\"></param>\n        /// <returns></returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\"></exception>\n        public static ISigner GetSigner(CertType certType)\n        {\n            switch (certType)\n            {\n                case CertType.RSA:\n                    return new SHA256WithRSASigner();\n                case CertType.SM:\n                    return new SM3WithSM2Signer();\n                default:\n                    throw new ArgumentOutOfRangeException(nameof(certType));\n            }\n        }\n\n        /// <summary>\n        /// 获取验签对象\n        /// </summary>\n        /// <param name=\"certType\"></param>\n        /// <returns></returns>\n        /// <exception cref=\"ArgumentOutOfRangeException\"></exception>\n        public static IVerifier GetVerifier(CertType certType)\n        {\n            switch (certType)\n            {\n                case CertType.RSA:\n                    return new SHA256WithRSAVerifier();\n                case CertType.SM:\n                    return new SM3WithSM2Verifier();\n                default:","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayHttpClient/TenPaySignerFactory.cs#L11-L47","documentation":"TenPaySignerFactory.GetSigner only supports CertType.RSA (SHA256WithRSASigner) and CertType.SM (SM3WithSM2Signer); any other CertType value reaches the default arm and throws ArgumentOutOfRangeException(nameof(certType)).","triggerScenarios":"Constructing TenPayHttpClient (which calls TenPayCertFactory/GetSigner) with an EncryptionType/CertType that is not RSA or SM — typically an invalid enum cast or an unbound default 0 value if the enum doesn't define it.","commonSituations":"Config value parsed into an undefined enum member; int cast to CertType; new CertType member added by a newer WeChat Pay scheme but the installed Senparc library version doesn't support it.","solutions":["Set EncryptionType to CertType.RSA (standard) or CertType.SM (国密) in your TenpayV3Setting.","Validate any config-sourced CertType with Enum.IsDefined before use.","If you need an unsupported scheme, upgrade the Senparc.Weixin.TenPay package to a version that supports it."],"exampleFix":"// before\nvar certType = (CertType)0; // undefined\n// after\nvar certType = CertType.RSA; // or CertType.SM","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(CertType), certType) || certType is not (CertType.RSA or CertType.SM))\n    throw new InvalidOperationException(\"EncryptionType must be RSA or SM.\");","typeGuard":"bool IsSupportedCertType(CertType t) => t is CertType.RSA or CertType.SM;","tryCatchPattern":"try { var signer = TenPaySignerFactory.GetSigner(certType); }\ncatch (ArgumentOutOfRangeException) { logger.LogError(\"Unsupported certType {CertType}\", certType); }","preventionTips":["Configure EncryptionType only with named enum members.","Validate enum config values at startup with Enum.IsDefined.","Keep the Senparc.Weixin.TenPay package updated if you use 国密."],"tags":["enum","argument","signing","wechat-pay"],"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"}