MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentException

kinds must contain at least one value

Error message

kinds must contain at least one value

What it means

`PackIconKindGroup` (MaterialDesignDemo.Shared) groups multiple icon-kind names under one canonical kind. Its constructor requires the `kinds` enumeration to contain at least one element; otherwise it throws `ArgumentException` because it must pick `allValues.First()` as the canonical `Kind`.

Source

Thrown at src/MaterialDesignDemo.Shared/Domain/PackIconKindGroup.cs:9

namespace MaterialDesignDemo;

public class PackIconKindGroup
{
    public PackIconKindGroup(IEnumerable<string> kinds)
    {
        if (kinds is null) throw new ArgumentNullException(nameof(kinds));
        var allValues = kinds.ToList();
        if (!allValues.Any()) throw new ArgumentException($"{nameof(kinds)} must contain at least one value");
        Kind = allValues.First();
        Aliases = allValues
            .OrderBy(x => x, StringComparer.InvariantCultureIgnoreCase)
            .ToArray();
    }

    public string Kind { get; }
    public string[] Aliases { get; }
}

View on GitHub (pinned to 98edec3a0b)

Solutions

  1. Filter out empty groups before constructing: `if (!kinds.Any()) continue;`.
  2. Ensure the source name list always includes the canonical kind name plus any aliases.
  3. Validate inputs in the caller and log/skip rather than construct.
  4. Add a unit test that groups built from the full icon name set are never empty.

Example fix

// before
var group = new PackIconKindGroup(filteredKinds); // throws if empty

// after
if (filteredKinds is null || !filteredKinds.Any()) continue;
var group = new PackIconKindGroup(filteredKinds);
Defensive patterns

Strategy: validation

Validate before calling

var kinds = GroupKinds(rawNames);
if (kinds is null || !kinds.Any()) continue;
var group = new PackIconKindGroup(kinds);

Type guard

static bool HasAnyKind(IEnumerable<string>? kinds)
    => kinds is not null && kinds.Any();

Prevention

When it happens

Trigger: Constructing `new PackIconKindGroup(kinds)` where `kinds` is empty (e.g. a LINQ filter/`Distinct` that produced zero results, or an empty array literal).

Common situations: Generating kind groups from icon-name data where a group ended up empty after deduplication; reflecting over `PackIconKind` names and filtering into an empty bucket; data entry missing the primary kind name.

Related errors


AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13). Data as JSON: /api/errors/cc4c32872058295d. Report an issue: GitHub.