8

I'm using VS 2015 with Resharper Ultimate for a Win Forms application and was doing something as simple as setting the text property of a button when I saw the blue squiggly line below the string.

Clicking on it converts the statement to the one I've retyped just below the problematic statement and there's no blue squiggly. Note that it's got the verbatim and the interpolation operators.

Also, setting the same string to another string with just interpolation seems to work fine. There's no characters to escape in this string. What's happening here?

enter image description here

0

3 Answers 3

4

As for verbatim string: Untick "ReSharper | Options | Code Editing | C# | Localization | Don't analyse verbatim string" checkbox and then ReSharper will show you such kind of suggestion for verbatim string as well.

As for why it shows squiggle for WinForms property but does not for a string: please refer to a webhelp article about "Localizable inspector" property. In case you would like to get the suggestion for all strings as well, you need to change "Localizable inspector" value to "Pessimistic"

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That answered all my questions.
3

You are setting a UI element's text to a string, and UI should be subject to localization.

On the other hand, interpolation is equivalent to just calling string.Format with default format provider.

It is assumed that UI elements will be populated from resources and that they will be formatted using specific culture. That is why ReSharper is sensitive to this particular use of string interpolation.

What you said about setting a different string to the interpolated string and then assigning that to the UI element, you are just playing tricks on ReSharper. It was not able to infer that you have assigned the UI element to the string which is not localized, but the problem is still there.

2 Comments

Thanks for your answer but If this is the case, how does adding the verbatim operator @ remove the need for UI localization as shown on the last line of the image?
I suppose that ReSharper somehow fails to see that the string is not localized when verbatim operator is used. As indicated above, the problem is still there, it's only the question whether tools will be able to raise the warning.
0

I had the same problem in VS2022 version 17.6.4 and ReSharper 2023.1.3. and Alexander Kurakin's solution did not work for me.
I too didn't want to change the interpolated string from: $"..." to a verbatim interpolation: $@"...".

The solution for me was to uncheck: "ReSharper | Options | Code Inspection | Inspection Severity | C# | Potential Code Quality Issues | Element is localizable"

Note, that for me strings like this are just a message for log, not for UI...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.