{"record":{"id":"c5cf764821ef6227","repo":"JeffreySu/WeiXinMPSDK","slug":"argumentoutofrangeexception-certtype-rsa-sm-only","errorCode":null,"errorMessage":"ArgumentOutOfRangeException (certType: RSA/SM only)","messagePattern":"ArgumentOutOfRangeException \\(certType: RSA/SM only\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayHttpClient/TenPaySignerFactory.cs","lineNumber":48,"sourceCode":"            }\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:\n                    throw new ArgumentOutOfRangeException(nameof(certType));\n            }\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":53,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/TenPayHttpClient/TenPaySignerFactory.cs#L30-L53","documentation":"TenPaySignerFactory.GetVerifier mirrors GetSigner for verification objects: CertType.RSA yields SHA256WithRSAVerifier, CertType.SM yields SM3WithSM2Verifier, and any other value throws ArgumentOutOfRangeException(nameof(certType)).","triggerScenarios":"TenPayHttpClient construction with an unsupported CertType/EncryptionType, since GetVerifier is invoked alongside GetSigner in the constructor; or direct calls to GetVerifier with an invalid enum value.","commonSituations":"Same family as the signer error: bad enum from config, int casts, or library versions lacking support for a newer certificate scheme.","solutions":["Set EncryptionType to RSA or SM in TenpayV3Setting.","Use Enum.IsDefined to validate config-derived CertType values.","Upgrade the package if a new certificate scheme is required."],"exampleFix":"// before\nservices.Configure(o => o.TenpayV3Setting.EncryptionType = (CertType)7);\n// after\nservices.Configure(o => o.TenpayV3Setting.EncryptionType = CertType.SM);","handlingStrategy":"validation","validationCode":"if (certType is not (CertType.RSA or CertType.SM))\n    throw new InvalidOperationException(\"Verifier supports only CertType.RSA or CertType.SM.\");","typeGuard":"bool IsSupportedVerifierType(CertType t) => t is CertType.RSA or CertType.SM;","tryCatchPattern":"try { var verifier = TenPaySignerFactory.GetVerifier(certType); }\ncatch (ArgumentOutOfRangeException) { logger.LogError(\"Unsupported certType for verifier: {CertType}\", certType); }","preventionTips":["Same guard as GetSigner: fix EncryptionType config to RSA or SM.","Test client construction at startup so enum mistakes surface immediately."],"tags":["enum","argument","verification","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"}