Description
The new C# 14 extension method syntax introduces a false positive for S2696 if the method updates a static field. This warning was not raised with the old syntax.
Reproducer
public static class ProvidersExtensions
{
private static IEnumerable<string>? _providers;
extension(IConfiguration configuration)
{
public IEnumerable<string> GetProvidersNewFormat()
{
// The following line triggers the S2696 warning.
_providers ??= configuration.GetSection("Providers").Get<string[]>() ?? [];
return _providers;
}
}
public static IEnumerable<string> GetProvidersOldFormat(this IConfiguration configuration)
{
// The following line does not trigger the warning.
_providers ??= configuration.GetSection("Providers").Get<string[]>() ?? [];
return _providers;
}
}
Product and Version
SonarAnalyzer.CSharp 10.18.0.131500
Description
The new C# 14 extension method syntax introduces a false positive for S2696 if the method updates a
staticfield. This warning was not raised with the old syntax.Reproducer
Product and Version
SonarAnalyzer.CSharp 10.18.0.131500