{"record":{"id":"39fe167df164d466","repo":"JeffreySu/WeiXinMPSDK","slug":"customsrequestdata","errorCode":null,"errorMessage":" 不能为空。","messagePattern":" 不能为空。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs","lineNumber":75,"sourceCode":"            Require(mch_id, \"mch_id\");\n            Require(customs, \"customs\");\n            Require(key, \"key\");\n        }\n\n        /// <summary>向签名处理器写入公共字段。</summary>\n        protected virtual void SetParameters(RequestHandler handler)\n        {\n            handler.SetParameter(\"appid\", appid);\n            handler.SetParameter(\"mch_id\", mch_id);\n            handler.SetParameter(\"customs\", customs);\n        }\n\n        /// <summary>校验字符串必填参数。</summary>\n        protected static void Require(string value, string parameterName)\n        {\n            if (string.IsNullOrWhiteSpace(value))\n            {\n                throw new ArgumentException(parameterName + \" 不能为空。\", parameterName);\n            }\n        }\n\n        /// <summary>按不变区域格式写入可选整数。</summary>\n        protected static void SetOptionalInt(RequestHandler handler,\n            string name, int? value)\n        {\n            if (value.HasValue)\n            {\n                handler.SetParameter(name,\n                    value.Value.ToString(CultureInfo.InvariantCulture));\n            }\n        }\n    }\n\n    /// <summary>\n    /// 支付订单海关报关请求。\n    /// <para>官方文档：https://pay.weixin.qq.com/doc/v3/merchant/4011985151</para>","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/CustomsRequestData.cs#L57-L93","documentation":"The Require helper in CustomsRequestData throws ArgumentException when a required string parameter for a WeChat Pay customs (报关) request is null, empty, or whitespace. The message is '<parameterName> 不能为空。'. It is the library's way of enforcing mandatory fields before a request is signed and sent.","triggerScenarios":"Calling Validate() on any CustomsRequestData subclass (e.g. the Declare/Query/Redeclare request data) without setting a required field — e.g. mch_customs_no, out_trade_no, etc. — leaves the field null/empty and Require fires during Validate.","commonSituations":"Developers construct the customs request object but forget to assign one field (often mch_customs_no or a merchant order number), or copy sample code that leaves optional-looking fields unassigned when they are actually required, or deserialize config from JSON where the key was missing.","solutions":["Find the parameterName in the exception message and set that property to a non-empty value before calling the declare/query API.","Verify the field against WeChat Pay's customs declaration documentation to confirm the exact required value format.","Add a pre-call validation/checks so missing fields fail fast in your own code."],"exampleFix":"// before\nvar data = new CustomsDeclareRequestData(key, appid, mch_id, null /* mch_customs_no */, out_trade_no, ...);\n// after\nvar data = new CustomsDeclareRequestData(key, appid, mch_id, \"YES customs code\", out_trade_no, ...);","handlingStrategy":"validation","validationCode":"// C#\nif (string.IsNullOrWhiteSpace(data.MchCustomsNo)) throw new InvalidOperationException(\"mch_customs_no is required before calling the customs API\");","typeGuard":"bool HasValue(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { await api.CallAsync(data); }\ncatch (ArgumentException ex) when (ex.Message.EndsWith(\"不能为空。\")) { log.LogError(ex, \"Missing customs request field: {Param}\", ex.ParamName); }","preventionTips":["Map each required field of the customs API doc to a constructor/property assignment in one place","Add unit tests constructing every request-data type with valid values","Use object initializers so omitted fields are visually obvious"],"tags":["argument-validation","weixin-tenpay","customs"],"backgroundTag":"missing-required-argument","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"}