HandyOrg/HandyControl · error
StatusException(status)
Error message
StatusException(status)
What it means
GetImageDecoders calls GdipGetImageDecodersSize and throws a StatusException when the returned GDI+ status is not Ok. This wraps native enumeration failure — GDI+ could not report how many decoders exist or the buffer size needed.
Solutions
- Check the status code in the exception to identify the GDI+ failure (e.g. NotInitialized).
- Verify GDI+ startup succeeded before enumerating decoders.
- Repair the system GDI+ installation (sfc /scannow) if failures are machine-specific.
- Cache codec lists at startup so a transient failure does not hit every decode call.
Example fix
// before
var status = InteropMethods.Gdip.GdipGetImageDecodersSize(out var numDecoders, out var size);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
// after
var status = InteropMethods.Gdip.GdipGetImageDecodersSize(out var numDecoders, out var size);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status, $"GetImageDecodersSize failed (status={status}); ensure GDI+ is initialized");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!InteropMethods.Gdip.ApplicationStarted)
{
throw new InvalidOperationException("GDI+ must be initialized before enumerating decoders.");
} Try / catch
try
{
var decoders = ImageCodecInfo.GetImageDecoders();
}
catch (StatusException ex)
{
logger.Error($"Decoder enumeration failed: {ex.Status}");
decoders = Array.Empty<ImageCodecInfo>(); // safe fallback
} Prevention
- Enumerate codecs once at startup and cache the result.
- Only call after successful GDI+ startup.
- Wrap native enumeration calls in try/catch with a cached fallback list.
When it happens
Trigger: Calling ImageCodecInfo.GetImageDecoders when GdipGetImageDecodersSize fails, which happens if GDI+ is not initialized or native GDI+ is in a bad state.
Common situations: Probing supported image formats on a machine with a broken/patched gdiplus.dll, or calling codec enumeration before GdiplusStartup completed.
Related errors
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/0d5fdde47ad4e3a8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/HandyControl_Shared/Data/Info/ImageCodecInfo.cs:62
public string MimeType { get; set; }
public ImageCodecFlags Flags { get; set; }
public int Version { get; set; }
public byte[][] SignaturePatterns { get; set; }
public byte[][] SignatureMasks { get; set; }
public static ImageCodecInfo[] GetImageDecoders()
{
ImageCodecInfo[] imageCodecs;
var status = InteropMethods.Gdip.GdipGetImageDecodersSize(out var numDecoders, out var size);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
var memory = Marshal.AllocHGlobal(size);
try
{
status = InteropMethods.Gdip.GdipGetImageDecoders(numDecoders, size, memory);
if (status != InteropMethods.Gdip.Ok)
{
throw InteropMethods.Gdip.StatusException(status);
}
imageCodecs = ConvertFromMemory(memory, numDecoders);
}
finally
{
Marshal.FreeHGlobal(memory);View on GitHub (pinned to 2c0875ebd6)