atifaziz/CSharpMinifier

Format specifiers can't contain curly braces

atifaziz opened this issue · 0 comments

Consider the following breaking change introduced with C# 11:

Format specifiers can't contain curly braces

Introduced in .NET SDK 6.0.200, Visual Studio 2022 version 17.1.

Format specifiers in interpolated strings can’t contain curly braces (either { or }). In previous versions {{ was interpreted as an escaped { and }} was interpreted as an escaped } char in the format specifier. Now the first } char in a format specifier ends the interpolation, and any { char is an error. This makes interpolated string processing consistent with the processing for xref:System.String.Format%2A?displayProperty=nameWithType:

using System;
Console.WriteLine($"{{{12:X}}}");
//prints now: "{C}" - not "{X}}"

X is the format for uppercase hexadecimal and C is the hexadecimal value for 12.

The workaround is to remove the extra braces in the format string.

You can learn more about this change in the associated roslyn issue.