{"record":{"id":"a778c981ba152b5b","repo":"JeffreySu/WeiXinMPSDK","slug":"openhardwarecallbackhandler","errorCode":null,"errorMessage":"参数不能为空。","messagePattern":"参数不能为空。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/OpenHardware/OpenHardwareCallbackHandler.cs","lineNumber":223,"sourceCode":"\n            return new OpenHardwareEncryptedCallbackReply\n            {\n                encrypt = encryptedReply.encrypt,\n                msgsignature = encryptedReply.msgsignature,\n                timestamp = timestamp,\n                nonce = encryptedReply.nonce\n            };\n        }\n\n        private static TMessage Deserialize<TMessage>(string plaintext)\n            where TMessage : OpenHardwareCallbackMessageBase\n            => JsonConvert.DeserializeObject<TMessage>(plaintext);\n\n        private static void EnsureNotEmpty(string value, string parameterName)\n        {\n            if (string.IsNullOrWhiteSpace(value))\n            {\n                throw new ArgumentException(\"参数不能为空。\", parameterName);\n            }\n        }\n    }\n}\n","sourceCodeStart":205,"sourceCodeEnd":228,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/OpenHardware/OpenHardwareCallbackHandler.cs#L205-L228","documentation":"EnsureNotEmpty is a private guard used by DecryptAndParse, ParsePlaintext and EncryptResponse in OpenHardwareCallbackHandler. It throws ArgumentException with the message 参数不能为空。 when a required string parameter (e.g. token, encodingAesKey, receiveId, timestamp, nonce, or the plaintext being parsed) is null, empty, or whitespace.","triggerScenarios":"Calling DecryptAndParse / ParsePlaintext / EncryptResponse with any required string argument left null or empty — most often an unconfigured token or EncodingAESKey, or an empty callback payload/plaintext passed to ParsePlaintext.","commonSituations":"Configuration values read from appsettings/environment not yet set (empty strings); decrypt step returning empty string due to an earlier failed decrypt; passing null timestamp/nonce when synthesizing test requests.","solutions":["Supply all required string arguments (token, encodingAesKey, receiveId, timestamp, nonce, plaintext) with non-empty values","Load configuration before the call and fail fast if token/aesKey/receiveId are missing","Ensure the decrypt step succeeded and produced non-empty plaintext before calling ParsePlaintext"],"exampleFix":"// before\nvar msg = OpenHardwareCallbackHandler.ParsePlaintext<MyMsg>(decryptResult); // decryptResult == \"\"\n// after\nif (string.IsNullOrWhiteSpace(decryptResult)) throw new InvalidOperationException(\"Decrypt produced empty plaintext\");\nvar msg = OpenHardwareCallbackHandler.ParsePlaintext<MyMsg>(decryptResult);","handlingStrategy":"validation","validationCode":"string[] required = { token, encodingAesKey, receiveId, timestamp, nonce };\nif (required.Any(string.IsNullOrWhiteSpace)) throw new InvalidOperationException(\"token/aesKey/receiveId/timestamp/nonce must all be non-empty\");","typeGuard":null,"tryCatchPattern":"try { var msg = OpenHardwareCallbackHandler.ParsePlaintext<TMessage>(plaintext); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Empty parameter {Param}\", ex.ParamName); return BadRequest(); }","preventionTips":["Validate configuration (token, aesKey, receiveId) at startup, fail fast if empty","Check decrypt output is non-empty before parsing","Treat whitespace-only config values as missing"],"tags":["argument-validation","empty-string","configuration","wechat-work"],"backgroundTag":"empty-required-field","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"}