File-New-Project/EarTrumpet · error · NotImplementedException

Rule type not found

Error message

Rule type not found

What it means

Inside FindReference, when a Manager.Reference has a Rules list (no static Value), ParseRule selects the first rule whose condition ('On') is true in the system-state table tab (Any, HighContrast, LightTheme, Transparency, UseAccentColor, UseAccentColorOnWindowBorders, AccentPolicySupportsTintColor). If no rule's On matches an active state, the LINQ chain yields null and the expression throws NotImplementedException("Rule type not found").

Source

Thrown at EarTrumpet/UI/Themes/BrushValueParser.cs:204

                }
                else
                {
                    var tab = new Dictionary<Rule.Kind, bool>();
                    tab.Add(Rule.Kind.Any, true);
                    tab.Add(Rule.Kind.HighContrast, SystemParameters.HighContrast);
                    tab.Add(Rule.Kind.LightTheme, isLight);
                    tab.Add(Rule.Kind.Transparency, SystemSettings.IsTransparencyEnabled && !SystemParameters.HighContrast);
                    tab.Add(Rule.Kind.UseAccentColor, SystemSettings.UseAccentColor && !isLight && !SystemParameters.HighContrast);
                    tab.Add(Rule.Kind.UseAccentColorOnWindowBorders, SystemSettings.UseAccentColorOnWindowBorders);
                    tab.Add(Rule.Kind.AccentPolicySupportsTintColor, AccentPolicyLibrary.AccentPolicySupportsTintColor);

                    Func<List<Rule>, string> ParseRule = null;
                    ParseRule = ruleList =>
                    {
                        var ret = ruleList.Where(
                            rule => tab[rule.On]).Select(
                            rule => (rule.Value != null) ? rule.Value : ParseRule(rule.Rules)).FirstOrDefault();
                        return ret != null ? ret : throw new NotImplementedException("Rule type not found");
                    };

                    string opacities = "";
                    var oItems = searchKey.Split('/').Skip(1).ToArray();
                    if (oItems.Length == 0)
                    {
                        // Nothing to do.
                    }
                    else if (oItems.Length == 1)
                    {
                        opacities = $"/{oItems[0]}";
                    }
                    else
                    {
                        opacities = $"/{oItems[0]}/{oItems[1]}";
                    }
                    outRef = Parse(element, ParseRule(reference.Rules) + opacities);
                    return true;

View on GitHub (pinned to aa894e51c2)

Solutions

  1. Add a Rule with Kind.Any (tab[Any] is always true) as the last/fallback rule so ParseRule always resolves.
  2. Ensure the rule set covers both LightTheme and Dark paths plus HighContrast.
  3. Audit every Reference.Rules list for an Any fallback.
  4. Add a design-time check that each Reference has at least one rule whose On is Any.

Example fix

// before: reference.Rules = new List<Rule> { new Rule { On = Rule.Kind.HighContrast, Value = "X" } };
//   -> throws when High Contrast is off
// after: append an Any fallback
//   reference.rings.Add(new Rule { On = Rule.Kind.Any, Value = "DefaultColor" });
Defensive patterns

Strategy: validation

Validate before calling

// ensure a Reference rules list always has an Any fallback before parsing
bool HasFallback(IEnumerable<Rule> rules) => rules.Any(r => r.On == Rule.Kind.Any);
if (!HasFallback(reference.Rules)) reference.Rules.Add(new Rule { On = Rule.Kind.Any, Value = "Default" });

Try / catch

try { outRef = Parse(element, ParseRule(reference.Rules) + opacities); }
catch (NotImplementedException ex) { Trace.WriteLine($"No matching rule: {ex.Message}"); outRef = null; return false; }

Prevention

When it happens

Trigger: A theme Reference is defined purely with rules that do not cover the current system state — e.g. only Rule.Kind.LightTheme rules while the system is in Dark mode, or only Rule.Kind.HighContrast rules while High Contrast is off, and no Rule.Kind.Any fallback.

Common situations: Authoring a Reference for one mode only and forgetting the Any/default branch; a rule set that depends on Transparency/UseAccentColor which are disabled on the user's machine; removing the catch-all Any rule during a refactor.

Related errors


AI-assisted analysis of File-New-Project/EarTrumpet@aa894e51c2 (2026-08-13). Data as JSON: /api/errors/be44d05e5f5e258b. Report an issue: GitHub.