CA1307 warning about string.Replace() but overload with StringComparison not available

I'm getting CA1307 warnings about using string.Replace(string, string?) instead of string.Replace(string, string?, System.StringComparison) (which I get). However, when I go to the line to add (for example) StringComparison.OrdinalIgnoreCase, both intellisense and compilation say that there's no overload. The same is the case for string.Contains().

Here is the warning:

Services\TemplateManager.cs(16,14): warning CA1307: The behavior of 'string.Replace(string, string?)' could vary based on the current user's locale settings. Replace this call in 'RSPlatform.Mail.Services.Template.Template(string, string, RSPlatform.Mail.TemplateType)' with a call to 'string.Replace(string, string?, System.StringComparison)'. [C:\<path>\<projectName>.csproj]

Here is an example line of code:

content = content.Replace(CRLF, LSCRLF);    // Insert LINE_SEPARATOR

Only two overloads are offered - the char and string variants (neither with the StringComparison parameter)

When I F12 the method the string metadata also only shows the two overloads which is stored here on my machine:


The code is in a class library with the following .csproj:


Any pointers would be grateful. Thanks

Read more here:

Content Attribution

This content was originally published by Chris Walsh at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: