{"record":{"id":"f002ae3321e5e5eb","repo":"HandyOrg/HandyControl","slug":"stream-null","errorCode":null,"errorMessage":"stream null","messagePattern":"stream null","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs","lineNumber":168,"sourceCode":"            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\");\n\n        var status = InteropMethods.Gdip.GdipCreateBitmapFromStream(new GPStream(stream), 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, null, stream);\n    }","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs#L150-L186","documentation":"GifImage.CreateSourceFromStream creates the native GDI+ bitmap from the supplied stream and throws ArgumentException('stream null') when the stream is null. It is called by GifImage initialization paths and by GetGifStreamFromPack, so a failed resource lookup can surface as this error.","triggerScenarios":"Passing a null Stream to CreateSourceFromStream, or GetGifStreamFromPack returning null (e.g. a pack URI that does not resolve) and then being fed into this method.","commonSituations":"Misspelled pack URIs for embedded GIFs; resource Build Action not set to Resource; stream already disposed/closed and nulled by caller.","solutions":["Check the stream for null before creating the GifImage and handle the missing-resource case","Verify the pack URI and that the GIF is embedded as a Resource in the project","Wrap the creation in try/catch (ArgumentException) or use an ImageFailed handler"],"exampleFix":"// before\nvar stream = GetGifStreamFromPack(uri);\nvar gif = new GifImage { Source = stream }; // throws when null\n// after\nvar stream = GetGifStreamFromPack(uri);\nif (stream != null)\n    var gif = new GifImage { Source = stream };","handlingStrategy":"validation","validationCode":"if (stream != null) { var gif = new GifImage { Source = stream }; }","typeGuard":"static bool HasStream(Stream? s) => s != null;","tryCatchPattern":"try { return new GifImage { Source = stream }; }\ncatch (ArgumentException) { return null; }","preventionTips":["Check pack URIs and ensure GIFs are built as Resource","Null-check the result of GetGifStreamFromPack","Handle ImageFailed events for robust loading"],"tags":["gif","gdiplus","null-argument"],"backgroundTag":"null-argument","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"}