JeffreySu/WeiXinMPSDK · error · ArgumentException
参数不能为空。
Error message
参数不能为空。
What it means
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.
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
Example fix
// before
var msg = OpenHardwareCallbackHandler.ParsePlaintext<MyMsg>(decryptResult); // decryptResult == ""
// after
if (string.IsNullOrWhiteSpace(decryptResult)) throw new InvalidOperationException("Decrypt produced empty plaintext");
var msg = OpenHardwareCallbackHandler.ParsePlaintext<MyMsg>(decryptResult); Defensive patterns
Strategy: validation
Validate before calling
string[] required = { token, encodingAesKey, receiveId, timestamp, nonce };
if (required.Any(string.IsNullOrWhiteSpace)) throw new InvalidOperationException("token/aesKey/receiveId/timestamp/nonce must all be non-empty"); Try / catch
try { var msg = OpenHardwareCallbackHandler.ParsePlaintext<TMessage>(plaintext); }
catch (ArgumentException ex) { logger.LogError(ex, "Empty parameter {Param}", ex.ParamName); return BadRequest(); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- AppId 不能为空。
- AppId 不能为空。
- ArgumentNullException (response is null)
- OpenHardwareCallbackCryptException (encrypt failed…
- ArgumentNullException (request is null)
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/a778c981ba152b5b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/OpenHardware/OpenHardwareCallbackHandler.cs:223
return new OpenHardwareEncryptedCallbackReply
{
encrypt = encryptedReply.encrypt,
msgsignature = encryptedReply.msgsignature,
timestamp = timestamp,
nonce = encryptedReply.nonce
};
}
private static TMessage Deserialize<TMessage>(string plaintext)
where TMessage : OpenHardwareCallbackMessageBase
=> JsonConvert.DeserializeObject<TMessage>(plaintext);
private static void EnsureNotEmpty(string value, string parameterName)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("参数不能为空。", parameterName);
}
}
}
}
View on GitHub (pinned to be573f6f94)