{"record":{"id":"746423810356f6d3","repo":"JeffreySu/WeiXinMPSDK","slug":"data","errorCode":null,"errorMessage":"data","messagePattern":"data","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/TenPayV3.Customs.cs","lineNumber":122,"sourceCode":"                GetCustomsUrl(CustomsRedeclarePath), data.ToXml(key), timeOut));\n        }\n\n        /// <summary>异步对支付订单重新进行海关申报。</summary>\n        public static async Task<CustomsRedeclareResult> CustomsRedeclareAsync(\n            CustomsRedeclareRequestData data, string key,\n            int timeOut = Config.TIME_OUT)\n        {\n            RequireCustomsData(data);\n            var xml = await PostCustomsAsync(GetCustomsUrl(CustomsRedeclarePath),\n                data.ToXml(key), timeOut).ConfigureAwait(false);\n            return new CustomsRedeclareResult(xml);\n        }\n\n        private static void RequireCustomsData(CustomsRequestDataBase data)\n        {\n            if (data == null)\n            {\n                throw new ArgumentNullException(\"data\");\n            }\n        }\n\n        private static string GetCustomsUrl(string path)\n        {\n            return Senparc.Weixin.Config.TenPayV3Host.TrimEnd('/') + path;\n        }\n\n        private static string PostCustoms(string url, string xml, int timeOut)\n        {\n            var bytes = Encoding.UTF8.GetBytes(xml);\n            using (var stream = new MemoryStream(bytes))\n            {\n                return RequestUtility.HttpPost(CommonDI.CommonSP, url, null,\n                    stream, timeOut: timeOut);\n            }\n        }\n","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPay/V3/Universal/Customs/TenPayV3.Customs.cs#L104-L140","documentation":"RequireCustomsData is a private guard used by all synchronous and asynchronous customs APIs (DeclareOrder, DeclareQuery, Redeclare). It throws ArgumentNullException named 'data' when the caller passes a null request-data object, since the library cannot build a request without it.","triggerScenarios":"Calling TenPayV3.CustomsDeclareOrder / CustomsDeclareOrderAsync / CustomsDeclareQuery / CustomsDeclareQueryAsync / CustomsRedeclare / CustomsRedeclareAsync with a null CustomsRequestDataBase instance.","commonSituations":"The request-data object was conditionally built (e.g. result of a factory method returning null when config was incomplete) or a variable was declared but never assigned before the API call.","solutions":["Construct the appropriate CustomsRequestData instance before calling the customs API.","Null-check the data object at the call site before invoking.","Fix whatever factory/configuration step is producing null instead of a data object."],"exampleFix":"// before\nCustomsDeclareRequestData data = null;\nawait tenPayV3.CustomsDeclareOrderAsync(data);\n// after\nvar data = new CustomsDeclareRequestData(key, appid, mchId, mchCustomsNo, outTradeNo, ...);\nawait tenPayV3.CustomsDeclareOrderAsync(data);","handlingStrategy":"type-guard","validationCode":"// C#\nif (data is null) throw new InvalidOperationException(\"Customs request data must be constructed before calling the API\");","typeGuard":"bool IsUsable<T>(T obj) where T : class => obj is not null; // if (IsUsable(data)) await tenPayV3.CustomsDeclareOrderAsync(data);","tryCatchPattern":"try { await tenPayV3.CustomsDeclareOrderAsync(data); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"data\") { log.LogError(\"Customs data was null — construction failed earlier\"); }","preventionTips":["Construct request objects inline at the call site rather than via nullable factories","Enable nullable reference types (nullable context) so the compiler flags possible-null data","Handle the factory's null return before invoking the API"],"tags":["null-argument","weixin-tenpay","customs"],"backgroundTag":"null-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"}