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:

%USERPROFILE%\AppData\Local\Temp\MetadataAsSource\15ed471edd80488c83ca4e3630c3149e\a25468945e7847cd8450af15ed506852\String.cs

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

<PropertyGroup>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <TargetFrameworks>net48;netcoreapp3.1;netstandard2.1</TargetFrameworks>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
</PropertyGroup>

Any pointers would be grateful. Thanks



Read more here: https://stackoverflow.com/questions/64401677/ca1307-warning-about-string-replace-but-overload-with-stringcomparison-not-ava

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: