In Visual Studio 2015, when I go to write an interpolated string in a variable by typing an opening curly bracket '{', to achieve the following:
var a = $"{}";
a second ending bracket is automatically inserted, colored red or pink, as so
var a = $"{}}"
After inserting a variable inside of the brackets '{}' and trying to compile, Visual Studio throws an error: "CS8086: A '}' character must be escaped (by doubling) in an interpolated string.". This makes sense, but doesn't at all explain why the second '}' appeared in the first place! I didn't want to write a '}' literal character; I just wanted to write a regular interpolated string - one '}' for one '{'. Every time I go to use interpolated strings I'm forced to manually remove this anomalous second closing bracket in order to compile successfully.
Most curiously, it doesn't appear to happen all the time. If you remove the '{}}' from your interpolated string and type a single '{' again, you will end up with '{}' - just as you would have expected in the first place.
What's up with this behavior?
This is being caused by Resharper.
You can prove this by going to
Tools | Options | ReSharper | General | Suspend Now
and then try it again. The extra }
will not appear. (I tried with R# 10.0)
I've been working around this problem by pressing ^Z after R# has inserted an extra }
, but it's still a bit annoying.
I guess this should be reported as a bug on the R# site (unless it's already been fixed with a recent release).
[EDIT] I've reported it as a bug on the Resharper forums. My bug report should appear there once the mods have approved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With