{"record":{"id":"3a167849b547eb71","repo":"TheAlgorithms/C-Sharp","slug":"nameof-bitmapheight-should-be-greater-than-zero","errorCode":null,"errorMessage":"{nameof(bitmapHeight)} should be greater than zero","messagePattern":"(.+?) should be greater than zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/Mandelbrot.cs","lineNumber":61,"sourceCode":"    public static SKBitmap GetBitmap(\n        int bitmapWidth = 800,\n        int bitmapHeight = 600,\n        double figureCenterX = -0.6,\n        double figureCenterY = 0,\n        double figureWidth = 3.2,\n        int maxStep = 50,\n        bool useDistanceColorCoding = true)\n    {\n        if (bitmapWidth <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapWidth),\n                $\"{nameof(bitmapWidth)} should be greater than zero\");\n        }\n\n        if (bitmapHeight <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapHeight),\n                $\"{nameof(bitmapHeight)} should be greater than zero\");\n        }\n\n        if (maxStep <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(maxStep),\n                $\"{nameof(maxStep)} should be greater than zero\");\n        }\n\n        var bitmap = new SKBitmap(bitmapWidth, bitmapHeight);\n        var figureHeight = figureWidth / bitmapWidth * bitmapHeight;\n\n        // loop through the bitmap-coordinates\n        for (var bitmapX = 0; bitmapX < bitmapWidth; bitmapX++)\n        {\n            for (var bitmapY = 0; bitmapY < bitmapHeight; bitmapY++)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/Mandelbrot.cs#L43-L79","documentation":"Mandelbrot.GetBitmap validates bitmapHeight after bitmapWidth and throws ArgumentOutOfRangeException when bitmapHeight <= 0. A non-positive height cannot back an SKBitmap, so the render is aborted before allocation.","triggerScenarios":"Calling Algorithms.Other.Mandelbrot.GetBitmap with bitmapHeight <= 0, e.g. GetBitmap(800, 0) or GetBitmap(800, -50).","commonSituations":"Height computed from aspect-ratio math that divided by or multiplied into 0; UI layout reporting zero height at startup; config value missing and defaulting to 0.","solutions":["Pass a bitmapHeight > 0 (e.g. 600)","Validate height before the call and substitute a default","Check that any aspect-ratio/computed height cannot round or evaluate to 0 or below"],"exampleFix":"// before\nvar bmp = Mandelbrot.GetBitmap(800, computedHeight);\n// after\nvar bmp = Mandelbrot.GetBitmap(800, Math.Max(1, computedHeight));","handlingStrategy":"validation","validationCode":"if (bitmapHeight <= 0) throw new ArgumentException(\"bitmapHeight must be positive\", nameof(bitmapHeight));","typeGuard":"static bool IsValidDimension(int d) => d > 0;","tryCatchPattern":"try { var bmp = Mandelbrot.GetBitmap(width, height); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"bitmapHeight\")\n{\n    // retry with default height\n}","preventionTips":["Clamp computed heights with Math.Max(1, value)","Verify aspect-ratio math cannot yield 0 for small widths","Validate config values before passing them on"],"tags":["argument-out-of-range","fractal","bitmap","csharp"],"backgroundTag":"argument-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}