{"record":{"id":"c55a72b907bfb3bb","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"non-primary-hues-provided","errorCode":null,"errorMessage":"Non primary hues provided.","messagePattern":"Non primary hues provided\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignColors.Wpf/Swatch.cs","lineNumber":15,"sourceCode":"﻿namespace MaterialDesignColors;\n\n/// <summary>\n/// Defines a single colour swatch.\n/// </summary>\npublic class Swatch\n{\n    public Swatch(string name, IEnumerable<Hue> primaryHues, IEnumerable<Hue> secondaryHues)\n    {\n        if (name is null) throw new ArgumentNullException(nameof(name));\n        if (primaryHues is null) throw new ArgumentNullException(nameof(primaryHues));\n        if (secondaryHues is null) throw new ArgumentNullException(nameof(secondaryHues));\n\n        var primaryHuesList = primaryHues.ToList();\n        if (primaryHuesList.Count == 0) throw new ArgumentException(\"Non primary hues provided.\", nameof(primaryHues));\n\n        Name = name;\n        PrimaryHues = primaryHuesList;\n        var secondaryHuesList = secondaryHues.ToList();\n        SecondaryHues = secondaryHuesList;\n        ExemplarHue = primaryHuesList[ExemplarHueIndex];\n        if (SecondaryHueIndex >= 0 && SecondaryHueIndex < secondaryHuesList.Count)\n        {\n            SecondaryExemplarHue = secondaryHuesList[SecondaryHueIndex];\n        }\n    }\n\n    public string Name { get; }\n\n    public Hue ExemplarHue { get; }\n\n    public Hue? SecondaryExemplarHue { get; }\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignColors.Wpf/Swatch.cs#L1-L33","documentation":"`Swatch` (MaterialDesignColors.Wpf) represents a named colour swatch and requires at least one primary hue to pick an `ExemplarHue`. Its constructor throws `ArgumentException` if `primaryHues` resolves to an empty list, because the exemplar lookup `primaryHuesList[ExemplarHueIndex]` would otherwise throw `ArgumentOutOfRangeException`.","triggerScenarios":"Constructing `new Swatch(name, primaryHues, secondaryHues)` with `primaryHues` being an empty enumeration (e.g. `Enumerable.Empty<Hue>()` or a filtered list that yielded nothing).","commonSituations":"A custom swatch provider that filters hues and returns none; a malformed/empty theme resource assembly; code that builds swatches dynamically and passes an empty source collection.","solutions":["Ensure the primaryHues collection passed to the `Swatch` constructor contains at least one `Hue`.","Skip/handle the empty case upstream: `if (!primaryHues.Any()) continue;` before constructing the swatch.","If building a custom `SwatchesProvider`, validate the resource assembly actually defines primary hue entries.","Unit-test custom swatch generation against empty inputs."],"exampleFix":"// before\nvar swatch = new Swatch(\"Red\", Enumerable.Empty<Hue>(), secondaryHues); // throws\n\n// after\nvar primaryHues = BuildPrimaryHues();\nif (primaryHues.Count == 0) continue;\nvar swatch = new Swatch(\"Red\", primaryHues, secondaryHues);","handlingStrategy":"validation","validationCode":"var primary = BuildPrimaryHues();\nif (primary is null || primary.Count == 0) continue;\nvar swatch = new Swatch(name, primary, secondary);","typeGuard":"static bool HasPrimaryHues(IEnumerable<Hue> hues)\n    => hues is not null && hues.Any();","tryCatchPattern":null,"preventionTips":["Validate custom swatch sources contain primary hues before constructing Swatch.","Unit-test swatch builders against empty/filtered inputs.","Use the official MaterialDesignColors resource assemblies."],"tags":["wpf","theming","swatch","material-design","validation","constructor"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}