HandyOrg/HandyControl · error · InvalidEnumArgumentException

icon

Error message

icon

What it means

Validation helper in MessageBox.CreateMessageBox: throws InvalidEnumArgumentException for 'icon' when the MessageBoxImage value is not a defined member (None, Hand, Question, Exclamation, Asterisk, Stop, Error, Warning, Information). It fires when an out-of-range icon enum reaches the factory.

Solutions

  1. Map public helper methods (Success/Info/Warning/Error/Fatal/Ask) to fixed valid MessageBoxImage constants
  2. Reject or default undefined icon values at the API boundary before CreateMessageBox
  3. Validate with Enum.IsDefined before calling the factory
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    }

    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
        {
            Message = messageBoxText,
            Owner = ownerWindow,
            WindowStartupLocation =
                ownerIsNull ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner,
            ShowTitle = true,

View on GitHub (pinned to 2c0875ebd6)