HandyOrg/HandyControl · error · ArgumentException
stream null
Error message
stream null
What it means
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.
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
Example fix
// before
var stream = GetGifStreamFromPack(uri);
var gif = new GifImage { Source = stream }; // throws when null
// after
var stream = GetGifStreamFromPack(uri);
if (stream != null)
var gif = new GifImage { Source = stream }; Defensive patterns
Strategy: validation
Validate before calling
if (stream != null) { var gif = new GifImage { Source = stream }; } Type guard
static bool HasStream(Stream? s) => s != null;
Try / catch
try { return new GifImage { Source = stream }; }
catch (ArgumentException) { return null; } Prevention
- Check pack URIs and ensure GIFs are built as Resource
- Null-check the result of GetGifStreamFromPack
- Handle ImageFailed events for robust loading
When it happens
Trigger: 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.
Common situations: Misspelled pack URIs for embedded GIFs; resource Build Action not set to Resource; stream already disposed/closed and nulled by caller.
Related errors
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/f002ae3321e5e5eb.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs:168
throw InteropMethods.Gdip.StatusException(status);
status = InteropMethods.Gdip.GdipImageForceValidation(new HandleRef(null, bitmap));
if (status != InteropMethods.Gdip.Ok)
{
InteropMethods.Gdip.GdipDisposeImage(new HandleRef(null, bitmap));
throw InteropMethods.Gdip.StatusException(status);
}
SetNativeImage(bitmap);
EnsureSave(this, filename, null);
}
private void CreateSourceFromStream(Stream stream)
{
if (stream == null)
throw new ArgumentException("stream null");
var status = InteropMethods.Gdip.GdipCreateBitmapFromStream(new GPStream(stream), out var bitmap);
if (status != InteropMethods.Gdip.Ok)
throw InteropMethods.Gdip.StatusException(status);
status = InteropMethods.Gdip.GdipImageForceValidation(new HandleRef(null, bitmap));
if (status != InteropMethods.Gdip.Ok)
{
InteropMethods.Gdip.GdipDisposeImage(new HandleRef(null, bitmap));
throw InteropMethods.Gdip.StatusException(status);
}
SetNativeImage(bitmap);
EnsureSave(this, null, stream);
}View on GitHub (pinned to 2c0875ebd6)