{"record":{"id":"7b1e016faa8b4bd6","repo":"HandyOrg/HandyControl","slug":"statusexception-status","errorCode":null,"errorMessage":"StatusException(status)","messagePattern":"StatusException\\(status\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs","lineNumber":374,"sourceCode":"            if (count <= 0)\n            {\n                return new Guid[0];\n            }\n\n            var size = Marshal.SizeOf(typeof(Guid));\n\n            var buffer = Marshal.AllocHGlobal(checked(size * count));\n            if (buffer == IntPtr.Zero)\n            {\n                throw InteropMethods.Gdip.StatusException(InteropMethods.Gdip.OutOfMemory);\n            }\n\n            status = InteropMethods.Gdip.GdipImageGetFrameDimensionsList(new HandleRef(this, NativeImage), buffer, count);\n\n            if (status != InteropMethods.Gdip.Ok)\n            {\n                Marshal.FreeHGlobal(buffer);\n                throw InteropMethods.Gdip.StatusException(status);\n            }\n\n            var guids = new Guid[count];\n\n            try\n            {\n                for (var i = 0; i < count; i++)\n                {\n                    guids[i] = (Guid) InteropMethods.PtrToStructure((IntPtr) ((long) buffer + size * i), typeof(Guid));\n                }\n            }\n            finally\n            {\n                Marshal.FreeHGlobal(buffer);\n            }\n\n            return guids;\n        }","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs#L356-L392","documentation":"GDI+ returned a non-Ok status from GdipImageGetFrameDimensionsList while enumerating the frame dimensions of the GIF. The library frees the unmanaged buffer and converts the native status code into a StatusException. It indicates the underlying native image handle rejected the frame-dimension query (corrupt image, wrong format, or disposed handle).","triggerScenarios":"Reading FrameDimensionsList on a GifImage whose native image is corrupt/truncated, or whose handle was disposed, so GdipImageGetFrameDimensionsList returns an error status like Win32Error or InvalidParameter.","commonSituations":"Loading a file renamed to .gif that is not actually a valid GIF; stream closed or modified while GifImage still uses it; accessing frames after Dispose.","solutions":["Verify the file is a genuine, complete GIF (check magic bytes 'GIF8') before loading","Keep the source stream open and unmodified for the lifetime of the GifImage","Do not access frame data after calling Dispose on the GifImage","Catch the StatusException and fall back to rendering the first frame"],"exampleFix":"// before\nvar dims = gif.FrameDimensionsList;\n// after\ntry { var dims = gif.FrameDimensionsList; }\ncatch (Exception ex) when (IsGdiPlusStatusError(ex)) { /* fallback: render frame 0 */ }","handlingStrategy":"try-catch","validationCode":"static bool LooksLikeGif(byte[] header) => header.Length >= 6 && header[0]=='G' && header[1]=='I' && header[2]=='F';","typeGuard":"static bool IsAlive(GifImage g) => g != null && !g.IsDisposed;","tryCatchPattern":"try { var dims = gif.FrameDimensionsList; }\ncatch (Exception ex) when (ex is ExternalException || ex.Message.Contains(\"StatusException\")) { /* single-frame fallback */ }","preventionTips":["Keep the source stream open for the image lifetime","Never access frames after Dispose","Fully download files before parsing"],"tags":["gdiplus","interop","gif","image"],"backgroundTag":"gdiplus-error","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"}