{"record":{"id":"255dce32ff4d71f0","repo":"JeffreySu/WeiXinMPSDK","slug":"tenpayapirequest","errorCode":null,"errorMessage":"文件名不能为空。","messagePattern":"文件名不能为空。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs","lineNumber":378,"sourceCode":"            Func<T> createDefaultInstance = null,\n            int maxFileBytes = 2 * 1024 * 1024)\n            where T : ReturnJsonBase, new()\n        {\n            return RequestMultipartCoreAsync(url, fileName, fileStream,\n                cancellationToken,\n                MultipartMetaFieldStyle.FilenameAndFileDigest, timeOut,\n                checkSign, createDefaultInstance, maxFileBytes);\n        }\n\n        private async Task<T> RequestMultipartCoreAsync<T>(string url, string fileName,\n            Stream fileStream, CancellationToken cancellationToken,\n            MultipartMetaFieldStyle metaFieldStyle, int timeOut, bool checkSign,\n            Func<T> createDefaultInstance, int? maxFileBytes = null)\n            where T : ReturnJsonBase, new()\n        {\n            if (string.IsNullOrWhiteSpace(fileName))\n            {\n                throw new ArgumentException(\"文件名不能为空。\", nameof(fileName));\n            }\n\n            _ = fileStream ?? throw new ArgumentNullException(nameof(fileStream));\n            if (timeOut <= 0 && timeOut != Timeout.Infinite)\n            {\n                throw new ArgumentOutOfRangeException(nameof(timeOut), \"超时时间必须大于 0，或使用 Timeout.Infinite。 \");\n            }\n            if (maxFileBytes.HasValue && maxFileBytes.Value <= 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(maxFileBytes),\n                    \"文件大小上限必须大于 0。\");\n            }\n            if (maxFileBytes.HasValue && fileStream.CanSeek &&\n                fileStream.Length - fileStream.Position > maxFileBytes.Value)\n            {\n                throw new InvalidDataException(\n                    $\"上传文件超过允许上限 {maxFileBytes.Value} 字节。\");\n            }","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/JeffreySu/WeiXinMPSDK/blob/be573f6f94bdbf718dd5f6cdecb137fbc7ff651e/src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/HttpHandlers/TenPayApiRequest.cs#L360-L396","documentation":"ArgumentException raised by RequestMultipartCoreAsync when fileName is null, empty, or whitespace. Multipart file uploads to WeChat Pay (e.g. image/bill upload APIs) require a file name for the form-data part and signature meta.","triggerScenarios":"Calling RequestMultipartAsync / RequestMultipartWithMaxSizeAsync / RequestMultipartWithFileDigestAsync / RequestMultipartWithFilenameAndFileDigestAsync with fileName = \"\" or null.","commonSituations":"Deriving the file name from Path.GetFileName on a path that was empty or a bare directory; a UI/upload layer that lost the original filename.","solutions":["Always supply a non-empty file name, e.g. Path.GetFileName(path) or an explicit name like \"image.jpg\"","Guard at the caller: if (string.IsNullOrWhiteSpace(fileName)) throw before building the request","Preserve the original filename through your upload pipeline"],"exampleFix":"// before\nawait apiRequest.RequestMultipartAsync(url, \"\", fileStream);\n// after\nvar fileName = Path.GetFileName(localPath); // e.g. \"logo.jpg\"\nawait apiRequest.RequestMultipartAsync(url, fileName, fileStream);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(fileName))\n    throw new ArgumentException(\"上传前需提供文件名\", nameof(fileName));","typeGuard":null,"tryCatchPattern":"try { await apiRequest.RequestMultipartAsync(url, fileName, fs); }\ncatch (ArgumentException ex) when (ex.ParamName == \"fileName\") { log.Error(\"文件名为空，无法上传\", ex); throw; }","preventionTips":["Use Path.GetFileName(path) to derive a guaranteed non-empty name","Validate uploaded-file metadata (name) before invoking WeChat Pay upload APIs","Default to a fallback name like \"file.bin\" only if acceptable to the endpoint"],"tags":["wechat-pay","multipart-upload","empty-required-field"],"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"}