VS Code Bug – Interpolation and Commented Lines, Workaround

This is a quick post with a workaround to a bug in VS Code that occurs when you use string with @$ – the verbatim character and the interpolation characters.

If you have a piece of code that looks like this –

string text = @$"any text as long as there is a new line
/*";

Everything that comes after it will look commented out, like so –

This is a bit annoying because all coloring is lost below that /*.

You might not have hit this, but if start using Pulumi for IaC in AWS, you will because many permissions on resources often end with /*, or if you want to print some slashes and stars to the console.

Fortunately, there is a very easy workaround! Use $@ instead of @$.

string text = $@"any text as long as there is a new line
/*";

Much better!

Leave a Reply

Your email address will not be published. Required fields are marked *