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

410 Views Asked by At

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 issue also occurs 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

0

There are 0 best solutions below