JeffreySu/WeiXinMPSDK · error · ArgumentException
文件名不能为空。
Error message
文件名不能为空。
What it means
UploadMemberImageAsync validates the image file name via ValidateBrandMemberImageFileName, which throws ArgumentException when the fileName is null, empty, or whitespace. The file name is needed both to derive the extension and to build the upload metadata for the brand member card image API.
Solutions
- Pass a non-empty file name including its extension (e.g. "member.png").
- If only a byte stream is available, supply a synthetic name with a valid extension like "image.jpg".
- Add a null/empty check in your upload pipeline before invoking the API.
Example fix
// before await apis.UploadMemberImageAsync(brandId, fileBytes, fileName: null); // after await apis.UploadMemberImageAsync(brandId, fileBytes, fileName: "member-avatar.png");
Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException("fileName is required for member image upload."); Type guard
bool hasFileName = !string.IsNullOrWhiteSpace(fileName);
Try / catch
try { await apis.UploadMemberImageAsync(brandId, bytes, fileName); }
catch (ArgumentException ex) { logger.Warn(ex, "Missing image file name"); throw new UserInputException("Please select a named image file."); } Prevention
- Always derive fileName from the original upload and preserve it end-to-end
- Fall back to a synthetic name with a valid extension when metadata is lost
- Check file-name inputs at the UI/form layer
When it happens
Trigger: Calling UploadMemberImageAsync with fileName = null, "", or " ", or deriving the file name from an upload whose original name was lost.
Common situations: Browser uploads stripped of filename metadata; using stream-only upload helpers and forgetting to pass a name; variables populated from config keys that are empty.
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 不能为空。
- 不能为空。
- out_trade_no、transaction_id、sub_order_no 和 sub_order_id…
- out_trade_no 和 transaction_id 至少填写一个。
AI-assisted analysis of JeffreySu/WeiXinMPSDK@be573f6f94 (2026-09-12).
Data as JSON: /api/errors/3585c69afeeef18b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Apis/BrandMemberCard/BrandMemberCardApis.cs:362
/// <returns>永久有效的媒体文件 URL。</returns>
public Task<BrandMemberCardImageUploadResultJson> UploadMemberImageAsync(
string fileName, Stream fileStream,
CancellationToken cancellationToken,
int timeOut = Config.TIME_OUT)
{
ValidateBrandMemberImageFileName(fileName);
const string path = "brand/card-member/media/image-upload";
return _request
.RequestMultipartWithFilenameAndFileDigestAsync<
BrandMemberCardImageUploadResultJson>(GetUrl(path),
fileName, fileStream, cancellationToken, timeOut);
}
private static void ValidateBrandMemberImageFileName(string fileName)
{
if (string.IsNullOrWhiteSpace(fileName))
{
throw new ArgumentException("文件名不能为空。",
nameof(fileName));
}
switch (Path.GetExtension(fileName)?.ToLowerInvariant())
{
case ".jpg":
case ".jpeg":
case ".bmp":
case ".png":
return;
default:
throw new ArgumentException(
"商家名片会员图片仅支持 JPG、JPEG、BMP 或 PNG。",
nameof(fileName));
}
}
private Task<T> PostAsync<T>(string path, object data, int timeOut)View on GitHub (pinned to be573f6f94)