{"record":{"id":"d69901956f4669dc","repo":"HandyOrg/HandyControl","slug":"interopmethods-gdip-statusexception-status","errorCode":null,"errorMessage":"InteropMethods.Gdip.StatusException(status)","messagePattern":"InteropMethods\\.Gdip\\.StatusException\\(status\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs","lineNumber":150,"sourceCode":"        }\n        catch\n        {\n            // ignored\n        }\n        finally\n        {\n            NativeImage = IntPtr.Zero;\n        }\n    }\n\n    private void CreateSourceFromFile(string filename)\n    {\n        filename = Path.GetFullPath(filename);\n\n        var status = InteropMethods.Gdip.GdipCreateBitmapFromFile(filename, out var bitmap);\n\n        if (status != InteropMethods.Gdip.Ok)\n            throw InteropMethods.Gdip.StatusException(status);\n\n        status = InteropMethods.Gdip.GdipImageForceValidation(new HandleRef(null, bitmap));\n\n        if (status != InteropMethods.Gdip.Ok)\n        {\n            InteropMethods.Gdip.GdipDisposeImage(new HandleRef(null, bitmap));\n            throw InteropMethods.Gdip.StatusException(status);\n        }\n\n        SetNativeImage(bitmap);\n\n        EnsureSave(this, filename, null);\n    }\n\n    private void CreateSourceFromStream(Stream stream)\n    {\n        if (stream == null)\n            throw new ArgumentException(\"stream null\");","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs#L132-L168","documentation":"GifImage.CreateSourceFromFile calls GdipCreateBitmapFromFile and throws the GDI+ StatusException when the native call returns a non-Ok status. This wraps a GDI+ error code (e.g. InvalidParameter, FileNotFound, OutOfMemory) into a managed exception while creating a GIF image from a file path. It indicates the file could not be loaded as a bitmap by GDI+.","triggerScenarios":"Calling GifImage with a Source path that does not exist, is locked, is not a valid image, or when the native GDI+ flat API returns an error status from GdipCreateBitmapFromFile.","commonSituations":"Typo or wrong working directory for a relative GIF path; file corrupted or unsupported format; file moved/deleted after build (pack vs filesystem confusion); permissions issues.","solutions":["Verify the file exists at the resolved full path (Path.GetFullPath) before loading","Confirm the file is a valid, supported image format","Check file read permissions and that the file is not locked by another process","Wrap the image creation in try-catch and fall back to a placeholder image"],"exampleFix":"// before\nvar gif = new GifImage { Source = path }; // throws if bad\n// after\nvar full = Path.GetFullPath(path);\nif (!File.Exists(full)) throw new FileNotFoundException(full);\nvar gif = new GifImage { Source = full };","handlingStrategy":"try-catch","validationCode":"if (!File.Exists(Path.GetFullPath(path))) throw new FileNotFoundException(path);","typeGuard":null,"tryCatchPattern":"try { return GifImage.CreateSourceFromFile(path); } catch (Exception ex) when (ex.Message.Contains(\"Gdip\")) { return PlaceholderImage; }","preventionTips":["Resolve and verify paths before load","Checksum untrusted image files","Use pack URIs for embedded assets"],"tags":["gdiplus","image","file","handycontrol"],"backgroundTag":"file-not-found","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"}