Menu

List`1[System.Int32] is not a style: escaping interpolated values in Spectre.Console markup
πŸ“°

List`1[System.Int32] is not a style: escaping interpolated values in Spectre.Console markup

DEV Community: dotnetΒ·Grant Totinov, M. Eng.Β·8 days ago
#gNO16gHL
#devtodotnet#devto#dev#string#format
Reading 0:00
15s threshold

Spectre.Console uses square brackets for markup: [red]error[/] prints "error" in red. Any literal [ in your text has to be escaped as [[ , otherwise the parser tries to read it as a style.

MarkupInterpolated and MarkupLineInterpolated exist so you don't have to think about that for values you interpolate. You write $"Hello {name}" and the library escapes name for you. Issue #1763 , opened by @yaakov-h , showed that this only worked when the value was a string . My fix is #2118 , merged on 12 May 2026 and released in 0.56.0 .

The bug

The issue's repro is short:

class CoolThing { public override string ToString () => "This[contains, braces]." ; }

AnsiConsole . MarkupLineInterpolated ( $"I have a { thing } " ); // InvalidOperationException: Could not find color or style 'contains,'.

Enter fullscreen mode

Exit fullscreen mode

The detail I liked most in the report was the workaround.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.