{"record":{"id":"611bb641f0444c04","repo":"AvaloniaUI/Avalonia","slug":"size-should-be-1-1","errorCode":null,"errorMessage":"Size should be >= (1,1)","messagePattern":"Size should be >= \\(1,1\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs","lineNumber":127,"sourceCode":"        /// <summary>\n        /// Loads a Bitmap from a stream and decodes at the desired height. Aspect ratio is maintained.\n        /// This is more efficient than loading and then resizing.\n        /// </summary>\n        /// <param name=\"stream\">The stream to read the bitmap from. This can be any supported image format.</param>\n        /// <param name=\"height\">The desired height of the resulting bitmap.</param>\n        /// <param name=\"interpolationMode\">The <see cref=\"BitmapInterpolationMode\"/> to use should any scaling be required.</param>\n        /// <returns>An instance of the <see cref=\"WriteableBitmap\"/> class.</returns>\n        public new static WriteableBitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)\n        {\n            var ri = GetFactory();\n\n            return new WriteableBitmap(ri.LoadWriteableBitmapToHeight(stream, height, interpolationMode));\n        }\n\n        private static (IBitmapImpl, BitmapMemory?) CreatePlatformImpl(PixelSize size, in Vector dpi, PixelFormat? format, AlphaFormat? alphaFormat)\n        {\n            if (size.Width <= 0 || size.Height <= 0)\n                throw new ArgumentException(\"Size should be >= (1,1)\", nameof(size));\n            \n            var ri = GetFactory();\n\n            PixelFormat finalFormat = format ?? ri.DefaultPixelFormat;\n            AlphaFormat finalAlphaFormat = alphaFormat ?? ri.DefaultAlphaFormat;\n\n            if (ri.IsSupportedBitmapPixelFormat(finalFormat))\n                return (ri.CreateWriteableBitmap(size, dpi, finalFormat, finalAlphaFormat), null);\n\n            if (!PixelFormatReader.SupportsFormat(finalFormat))\n                throw new NotSupportedException($\"Pixel format {finalFormat} is not supported\");\n\n            finalAlphaFormat = finalFormat.HasAlpha ? finalAlphaFormat : Platform.AlphaFormat.Opaque;\n\n            var impl = ri.CreateWriteableBitmap(size, dpi, PixelFormat.Rgba8888, finalAlphaFormat);\n            return (impl, new BitmapMemory(finalFormat, finalAlphaFormat, size));\n        }\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Imaging/WriteableBitmap.cs#L109-L145","documentation":"WriteableBitmap.CreatePlatformImpl throws ArgumentException(nameof(size)) when size.Width <= 0 || size.Height <= 0. A bitmap must have at least one pixel in each dimension. This guard runs in every constructor path and DecodeToHeight, so a decoded stream that yields zero dimensions also surfaces here.","triggerScenarios":"Constructing a WriteableBitmap with PixelSize(0,0) or negative dimensions; calling DecodeToHeight on a corrupt/empty stream that decodes to a zero-size image.","commonSituations":"Passing a UI Size or a default PixelSize; decoding a truncated or unsupported image file; computing dimensions from DPI/scale and rounding to zero.","solutions":["Ensure width and height are >= 1 before constructing.","Validate the stream decodes to a non-zero size (decode to a Bitmap first to inspect PixelSize).","Guard callers that derive size from external input against zero/negative values."],"exampleFix":"// before\nvar wb = new WriteableBitmap(new PixelSize(0, 0), dpi, PixelFormat.Bgra8888);\n\n// after\nif (size.Width < 1 || size.Height < 1)\n    throw new ArgumentException(\"Bitmap size must be at least 1x1.\", nameof(size));\nvar wb = new WriteableBitmap(new PixelSize(Math.Max(1,size.Width), Math.Max(1,size.Height)), dpi, PixelFormat.Bgra8888);","handlingStrategy":"validation","validationCode":"if (size.Width < 1 || size.Height < 1)\n    throw new ArgumentException(\"Size must be >= (1,1).\", nameof(size));\nvar wb = new WriteableBitmap(size, dpi, PixelFormat.Bgra8888);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate dimensions derived from external input before constructing.","When decoding, verify the stream yields a non-zero PixelSize first.","Avoid passing UI Size (double) where PixelSize (int) is required."],"tags":["imaging","writeablebitmap","argument","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}