HandyOrg/HandyControl · error · ArgumentOutOfRangeException

ArgumentOutOfRangeException

Error message

ArgumentOutOfRangeException

What it means

Validation guard in GetHatchData: the HatchStyle value passed in (or computed upstream and fed into the hatch-pattern lookup) falls outside the supported hatch-style range, so the array indexer throws when selecting the pattern data. The real fault lies in the caller supplying an undefined/out-of-range style — the sentinel exception marks an invalid enum input rather than a rendering failure.

Solutions

  1. Validate hatchStyle with Enum.IsDefined(typeof(HatchStyle), value) (plus range check for non-flags values) before calling GetHatchData, falling back to a default style like Solid
  2. Clamp the style: 'hatchStyle = (HatchStyle)Math.Clamp((int)hatchStyle, (int)HatchStyle.Min, (int)HatchStyle.Max);' before indexing the pattern array
  3. Return null (or a default pattern) from GetHatchData for unsupported styles and let the caller render a plain brush instead of crashing
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Shared/HandyControl_Shared/Tools/Generator/HatchBrushGenerator.cs:114 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/4c43679a878ef7b2. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Tools/Generator/HatchBrushGenerator.cs:114

                        Brush = new SolidColorBrush(backColor),
                        Geometry = new RectangleGeometry(new Rect(0, 0, 8, 8))
                    },
                    new GeometryDrawing
                    {
                        Brush = new SolidColorBrush(foreColor),
                        Geometry = foreGeometryGroup
                    }
                }
            }
        };
        RenderOptions.SetCachingHint(drawingBrush, CachingHint.Cache);

        return drawingBrush;
    }

    private byte[] GetHatchData(HatchStyle hatchStyle) =>
        hatchStyle < HatchStyle.Horizontal || hatchStyle > HatchStyle.SolidDiamond
            ? throw new ArgumentOutOfRangeException(nameof(hatchStyle))
            : HatchBrushes[(int) hatchStyle];
}

View on GitHub (pinned to 2c0875ebd6)