{"record":{"id":"057dd52058dd851a","repo":"HandyOrg/HandyControl","slug":"nativehandle0","errorCode":null,"errorMessage":"NativeHandle0","messagePattern":"NativeHandle0","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs","lineNumber":313,"sourceCode":"        {\n        }\n        // possible exceptions for setting/getting the position inside dataStream\n        catch (NotSupportedException)\n        {\n        }\n        catch (ObjectDisposedException)\n        {\n        }\n        // possible exception when reading stuff into dataStream\n        catch (ArgumentException)\n        {\n        }\n    }\n\n    internal void SetNativeImage(IntPtr handle)\n    {\n        if (handle == IntPtr.Zero)\n            throw new ArgumentException(\"NativeHandle0\");\n\n        NativeImage = handle;\n    }\n\n    internal Guid RawGuid\n    {\n        get\n        {\n            var guid = new Guid();\n\n            var status = InteropMethods.Gdip.GdipGetImageRawFormat(new HandleRef(this, NativeImage), ref guid);\n\n            if (status != InteropMethods.Gdip.Ok)\n                throw InteropMethods.Gdip.StatusException(status);\n\n            return guid;\n        }\n    }","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs#L295-L331","documentation":"GifImage.SetNativeImage stores the native GDI+ image handle and throws ArgumentException('NativeHandle0') when the handle is IntPtr.Zero, because a zero handle means GDI+ failed to produce a valid image. Called from CreateSourceFromFile and CreateSourceFromStream.","triggerScenarios":"Creating a GifImage from a file/stream where the preceding GdipCreateBitmapFromStream/GdipCreateBitmapFromFile returned a zero handle — typically a corrupt, missing, or non-image file.","commonSituations":"Corrupt or truncated GIF files; files that exist but are not valid images; GDI+ native failures swallowed upstream before the handle check.","solutions":["Validate the image file/stream (e.g. try loading with a standard Image decoder) before constructing GifImage","Catch ArgumentException and fall back to a static placeholder image","Re-export or re-download the GIF if the file is corrupt"],"exampleFix":"// before\nvar gif = new GifImage { Source = File.OpenRead(path) }; // corrupt file -> Zero handle -> throws\n// after\ntry { var gif = new GifImage { Source = File.OpenRead(path) }; }\ncatch (ArgumentException) { ShowPlaceholderImage(); }","handlingStrategy":"try-catch","validationCode":"try { using var probe = System.Drawing.Image.FromStream(stream); } catch { return false; }","typeGuard":"static bool IsValidGif(Stream s) => s != null && s.Length > 6;","tryCatchPattern":"try { return GifImage.CreateSourceFromStream(stream); }\ncatch (ArgumentException) { ShowPlaceholder(); return null; }","preventionTips":["Verify GIF integrity before constructing GifImage","Catch native GDI+ failures with placeholder fallback","Re-export corrupt assets"],"tags":["gif","gdiplus","native-handle"],"backgroundTag":"invalid-argument-value","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"}