HandyOrg/HandyControl · error · InvalidEnumArgumentException

button

Error message

button

What it means

Validation helper in MessageBox.CreateMessageBox: throws InvalidEnumArgumentException for 'button' when the MessageBoxButton value passed to Show/CreateMessageBox is not one of the defined members (OK, OKCancel, YesNo, YesNoCancel). It fires when callers pass an undefined/cast enum value.

Solutions

  1. Pass only defined MessageBoxButton values from the public Show/Success/Info/Warning/Error/Fatal/Ask entry points
  2. Constrain API surface so callers cannot supply arbitrary enum integers
  3. Add unit tests enumerating all valid MessageBoxButton members
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs:482 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/3411b213c2f5a2b0. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs:482

            SystemSounds.Asterisk.Play();
            messageBox.ShowDialog();
        }));

        return messageBox._messageBoxResult;
    }

    private static MessageBox CreateMessageBox(
        System.Windows.Window owner,
        string messageBoxText,
        string caption,
        MessageBoxButton button,
        MessageBoxImage icon,
        MessageBoxResult defaultResult
    )
    {
        if (!IsValidMessageBoxButton(button))
        {
            throw new InvalidEnumArgumentException(nameof(button), (int) button, typeof(MessageBoxButton));
        }

        if (!IsValidMessageBoxImage(icon))
        {
            throw new InvalidEnumArgumentException(nameof(icon), (int) icon, typeof(MessageBoxImage));
        }

        if (!IsValidMessageBoxResult(defaultResult))
        {
            throw new InvalidEnumArgumentException(nameof(defaultResult), (int) defaultResult,
                typeof(MessageBoxResult));
        }

        var ownerWindow = owner ?? WindowHelper.GetActiveWindow();
        var ownerIsNull = ownerWindow is null;

        return new MessageBox
        {

View on GitHub (pinned to 2c0875ebd6)