{"record":{"id":"c135d1a63a5ae821","repo":"babalae/better-genshin-impact","slug":"error-c135d1","errorCode":null,"errorMessage":"下载内容不是有效的图片。","messagePattern":"下载内容不是有效的图片。","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/BannerImageService.cs","lineNumber":204,"sourceCode":"        {\n            AllowAutoRedirect = true,\n            MaxAutomaticRedirections = 5,\n            UseCookies = false,\n            UseDefaultCredentials = false\n        })\n        {\n            Timeout = Timeout.InfiniteTimeSpan\n        };\n        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            {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/BannerImageService.cs#L186-L222","documentation":"Thrown by ValidateImage when SixLabors.ImageSharp's Image.Identify returns null — the downloaded file exists and was read, but ImageSharp could not parse any image metadata from it. This is treated as InvalidDataException because the bytes are not a usable image.","triggerScenarios":"The downloaded content is HTML (e.g. a 404/error page that still returned HTTP 200), a non-image binary, or a truncated/corrupt image where the header is unreadable but the file is non-empty.","commonSituations":"URL points to a web page rather than a direct image link; CDN returns an HTML interstitial with status 200; the response was cut short by the MaxDownloadBytes cap mid-header; the server serves a different content type than expected.","solutions":["Verify the URL resolves directly to an image file (open it in a browser and confirm it renders as an image, not a page).","Check the server's Content-Type header and HTTP status — an HTML body with 200 is the usual culprit.","Retry the download; transient corruption on slow links can truncate the header.","If the source is reliable, the file may be a format ImageSharp cannot detect — see error 463."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Inspect Content-Type before streaming to disk.\nif (!response.Content.Headers.ContentType?.MediaType?.StartsWith(\"image/\") == true)\n{\n    throw new InvalidDataException(\"响应不是图片类型。\", );\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    ValidateImage(tempPath);\n}\ncatch (InvalidDataException ex) when (ex.Message.Contains(\"不是有效的图片\"))\n{\n    // The URL did not yield a real image — prompt the user for a valid image URL.\n    logger.LogError(ex, \"Downloaded content is not a valid image\");\n}","preventionTips":["Verify URLs point directly to an image resource (not an HTML page) before downloading.","Check the Content-Type header in the response; reject non-image MIME types early.","Wrap ValidateImage callers so a bad URL surfaces a friendly message rather than crashing the UI."],"tags":["image","validation","download","banner-image"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}