File-New-Project/EarTrumpet · error · Exception

BrushValueParser Error

Error message

BrushValueParser Error: '{value}' {element}

What it means

The entire body of BrushValueParser.Parse is wrapped in try/catch that rethrows every failure as a new Exception("BrushValueParser Error: ...", ex). The real cause is in InnerException — typically one of the inner NotImplementedException throws (unknown theme key, rule-not-found, bad slashes) or a FormatException from color parsing. The wrapper preserves the offending value and element for diagnostics.

Solutions

  1. Read ex.InnerException to find the true failure (one of errors 7, 8, 10, 11 or a FormatException) and fix that specific cause.
  2. Validate the theme value string against the supported grammar (scope:key=value pairs, optional /opacity, known color names) before passing to Parse.
  3. Ensure any referenced Manager.References key is defined.
  4. Test with the target Windows build so Immersive color names resolve.

Example fix

// before: value = "Bacground=#FF0000"   // typo, not a known color -> wrapped error
// after:  value = "Background=#FF0000"
// diagnostic: catch (Exception ex) { var root = ex.InnerException ?? ex; Trace.WriteLine(root.Message); }
Defensive patterns

Strategy: try-catch

Validate before calling

// optional: validate grammar before Parse
static bool IsValidMarkup(string v)
{
    if (string.IsNullOrWhiteSpace(v)) return false;
    foreach (var seg in v.Split(','))
        foreach (var part in seg.Split('/'))
            if (part.IndexOf('=') < 0 && part.Length == 0) return false;
    return true;
}

Try / catch

try { return BrushValueParser.Parse(element, value); }
catch (Exception ex)
{
    var root = ex.InnerException ?? ex;
    Trace.WriteLine($"BrushValueParser failed for '{value}': {root.Message}");
    return new SolidColorBrush(Colors.HotPink); // mirror the in-parser fallback
}

Prevention

When it happens

Trigger: Any unhandled failure inside Parse: an unknown color name that is not a hex color, Immersive color, Colors/SystemColors property, nor a resolvable reference; a malformed opacity segment; a Reference whose rules do not match; the HighContrast/Dark/Light fallthroughs.

Common situations: Typo in a theme brush string; reference to an undefined Manager key; color name not present on the running Windows build (Immersive color missing); malformed "Color/0.5/0.2" opacity.

Related errors


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

Appendix: source

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

                        // But it will succeed when the element Loaded is called.
                        ret = Colors.HotPink;
                        Trace.WriteLine($"## BrushValueParser Parse FAILED ## '{value}' {element}");
                    }
                }
                else
                {
                    ret = color;
                }

                if (opacity > 0)
                {
                    ret.A = (byte)(opacity * 255);
                }
                return new SolidColorBrush(ret);
            }
            catch (Exception ex)
            {
                throw new Exception($"BrushValueParser Error: '{value}' {element}", ex);
            }
        }

        private static bool FindReference(DependencyObject element, string searchKey, out SolidColorBrush outRef)
        {
            bool isLight = Options.GetSource(element) == Options.SourceKind.App ? SystemSettings.IsLightTheme : SystemSettings.IsSystemLightTheme;
            var reference = Manager.Current.References.FirstOrDefault(r => r.Key == searchKey.Split('/')[0]);
            if (reference != null)
            {
                if (reference.Value != null)
                {
                    outRef = Parse(element, reference.Value);
                    return true;
                }
                else
                {
                    var tab = new Dictionary<Rule.Kind, bool>();
                    tab.Add(Rule.Kind.Any, true);

View on GitHub (pinned to aa894e51c2)