{"record":{"id":"ed0c1e15bb3c6d7e","repo":"HandyOrg/HandyControl","slug":"imagecodecinfo-is-null","errorCode":null,"errorMessage":"ImageCodecInfo is null","messagePattern":"ImageCodecInfo is null","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs","lineNumber":582,"sourceCode":"        InteropMethods.SelectObject(hdcDest, hOld);\n        InteropMethods.DeleteDC(hdcDest);\n        InteropMethods.ReleaseDC(_desktopWindowHandle, hdcSrc);\n\n        var status = InteropMethods.Gdip.GdipCreateBitmapFromHBITMAP(new HandleRef(null, hbitmap), new HandleRef(null, IntPtr.Zero), out var bitmap);\n        if (status != InteropMethods.Gdip.Ok) throw InteropMethods.Gdip.StatusException(status);\n\n        using var ms = new MemoryStream();\n        status = InteropMethods.Gdip.GdipGetImageEncodersSize(out var numEncoders, out var size);\n        if (status != InteropMethods.Gdip.Ok) throw InteropMethods.Gdip.StatusException(status);\n\n        var memory = Marshal.AllocHGlobal(size);\n        try\n        {\n            status = InteropMethods.Gdip.GdipGetImageEncoders(numEncoders, size, memory);\n            if (status != InteropMethods.Gdip.Ok) throw InteropMethods.Gdip.StatusException(status);\n\n            var codecInfo = ImageCodecInfo.ConvertFromMemory(memory, numEncoders).FirstOrDefault(item => item.FormatID.Equals(BmpGuid));\n            if (codecInfo == null) throw new Exception(\"ImageCodecInfo is null\");\n\n            var encoderParamsMemory = IntPtr.Zero;\n\n            try\n            {\n                var g = codecInfo.Clsid;\n                status = InteropMethods.Gdip.GdipSaveImageToStream(new HandleRef(this, bitmap),\n                    new InteropValues.ComStreamFromDataStream(ms), ref g,\n                    new HandleRef(null, encoderParamsMemory));\n            }\n            finally\n            {\n                if (encoderParamsMemory != IntPtr.Zero)\n                {\n                    Marshal.FreeHGlobal(encoderParamsMemory);\n                }\n            }\n","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs#L564-L600","documentation":"Guard in ScreenshotWindow thrown when the GDI+ image-encoder lookup returns no codecs (ImageCodecInfo lookup yields null), so the captured screenshot cannot be encoded to the requested format. It fires when GdipGetImageEncodersSize/GetImageEncoders finds no registered encoder for the requested mime type on the machine.","triggerScenarios":"Thrown at src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs:582 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the encoder array for null/empty before use and pick the first available encoder instead of assuming a specific codec","Fall back to saving the captured bitmap as PNG (GDI+ built-in) when the requested encoder is unavailable","Verify the mime type string passed to the encoder lookup is a well-known value (image/png, image/jpeg)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}