{"record":{"id":"00d3b0d2623fae46","repo":"babalae/better-genshin-impact","slug":"error-00d3b0","errorCode":null,"errorMessage":"下载内容不是支持的图片格式。","messagePattern":"下载内容不是支持的图片格式。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/BannerImageService.cs","lineNumber":213,"sourceCode":"        client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(\"BetterGI-Banner\", \"1.0\"));\n        return client;\n    }\n\n    private static void ValidateImage(string path)\n    {\n        try\n        {\n            var imageInfo = Image.Identify(path)\n                            ?? throw new InvalidDataException(\"下载内容不是有效的图片。\");\n            var pixelCount = checked((long)imageInfo.Width * imageInfo.Height);\n            if (pixelCount > MaxPixelCount)\n            {\n                throw new InvalidDataException($\"图片像素数量超过 {MaxPixelCount:N0} 限制。\");\n            }\n        }\n        catch (UnknownImageFormatException ex)\n        {\n            throw new InvalidDataException(\"下载内容不是支持的图片格式。\", ex);\n        }\n    }\n\n    private static void TryDeleteFile(string path)\n    {\n        try\n        {\n            if (File.Exists(path))\n            {\n                File.Delete(path);\n            }\n        }\n        catch (IOException)\n        {\n            // 临时文件清理失败不应覆盖原始下载异常。\n        }\n        catch (UnauthorizedAccessException)\n        {","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/BannerImageService.cs#L195-L231","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    ValidateImage(tempPath);\n}\ncatch (InvalidDataException ex) when (ex.InnerException is UnknownImageFormatException)\n{\n    // Format not supported — ask the user for a JPEG/PNG/BMP/GIF.\n    logger.LogError(ex, \"Unsupported image format\");\n}","preventionTips":["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."],"tags":["image","format","validation","banner-image","imagesharp"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}