babalae/better-genshin-impact · error · InvalidDataException
下载内容不是支持的图片格式。
Error message
下载内容不是支持的图片格式。
What it means
Thrown when SixLabors.ImageSharp raises UnknownImageFormatException during Image.Identify — the file's magic bytes do not match any image format decoder that ImageSharp has registered. The service wraps it as InvalidDataException with a clearer message.
Source
Thrown at BetterGenshinImpact/Service/BannerImageService.cs:213
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("BetterGI-Banner", "1.0"));
return client;
}
private static void ValidateImage(string path)
{
try
{
var imageInfo = Image.Identify(path)
?? throw new InvalidDataException("下载内容不是有效的图片。");
var pixelCount = checked((long)imageInfo.Width * imageInfo.Height);
if (pixelCount > MaxPixelCount)
{
throw new InvalidDataException($"图片像素数量超过 {MaxPixelCount:N0} 限制。");
}
}
catch (UnknownImageFormatException ex)
{
throw new InvalidDataException("下载内容不是支持的图片格式。", ex);
}
}
private static void TryDeleteFile(string path)
{
try
{
if (File.Exists(path))
{
File.Delete(path);
}
}
catch (IOException)
{
// 临时文件清理失败不应覆盖原始下载异常。
}
catch (UnauthorizedAccessException)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Use a universally supported format: JPEG, PNG, BMP, or GIF.
- If WebP support is required, ensure the SixLabors.ImageSharp.Webp NuGet package is referenced and registered in the ImageSharp Configuration.
- Re-encode the source image to JPEG/PNG before hosting it.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
ValidateImage(tempPath);
}
catch (InvalidDataException ex) when (ex.InnerException is UnknownImageFormatException)
{
// Format not supported — ask the user for a JPEG/PNG/BMP/GIF.
logger.LogError(ex, "Unsupported image format");
} Prevention
- Host banners as JPEG or PNG — the most broadly supported formats.
- If WebP/AVIF support is needed, add and register the corresponding SixLabors.ImageSharp format package.
- Validate the source format before offering it as a banner URL.
When it happens
Trigger: The downloaded content is an image format ImageSharp does not support by default (e.g. WebP without the SixLabors.ImageSharp.Webp package, AVIF, HEIC, SVG, ICO), or the file is mislabeled (extension says .jpg but bytes are something else).
Common situations: User picks a modern format URL (WebP/AVIF) that the bundled ImageSharp configuration cannot decode; URL serves SVG; a server-side format converter is misconfigured.
Related errors
- 下载内容不是有效的图片。
- 图片像素数量超过 {MaxPixelCount:N0} 限制。
- milliseconds 不能小于 0
- 当前动作已经设置完成条件,不能再次修改或添加
- 等待 {targetDescription} 超时({timeout}ms)
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/00d3b0d2623fae46.
Report an issue: GitHub.