Repository: dotnet/roslyn-analyzers

Issue #4755: CA1508 false positive on String.IsNullOrWhiteSpace (in 5.0.2)
Created: 2021-01-30T13:12:43Z
I see that #4439 recently fixed something that sounded like this, and apparently the tag lists that it's fixed in 5.0.1.  However, my dotnet --info reports that I'm on version 5.0.2 (<AnalysisLevel>latest</AnalysisLevel>), and I still seem to be able to repro a very similar CA1508 false positive.
Steps

Save the three following files to a folder.
dotnet build --no-incremental

Actual: CA1508 on the string.IsNullOrWhiteSpace call.
Expected: no CA1508 warnings
My dotnet --info Output (not one of the three files)
.NET SDK (reflecting any global.json):
 Version:   5.0.102
 Commit:    71365b4d42

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support):
  Version: 5.0.2
  Commit:  cb5f173b96

.NET SDKs installed:
  5.0.101 [C:\Program Files\dotnet\sdk]
  5.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download


Here are the three files:
ConsoleApp0.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisLevel>latest</AnalysisLevel>
  </PropertyGroup>

</Project>
.editorconfig
[*.cs]
dotnet_diagnostic.CA1508.severity = warning
Program.cs
using System;
using System.Linq;

static class Helpers
{
    static void Main()
    {
        Helper("a");
    }

    static void Helper(string s)
    {
        if (s is null)
        {
            throw new ArgumentNullException(nameof(s));
        }

        if (string.IsNullOrWhiteSpace(s))
        {
            throw new ArgumentException("Cannot be blank", nameof(s));
        }

        Console.WriteLine(s);
    }
}

Duplicate issue #4506: Add documentation on how to update to newer versions
Created: 2020-12-05T06:15:15Z
Version 5.0.1 has just shipped and I can't figure out how to get this version into my projects.
I've tried updating <AnalysisLevel> property in my project file - however I can't verify that the newer version is actually being used. Visual Studio still shows "5.0". In fact, even if I set the property to the non-existing version of "5.0.8" in my project file everything still builds fine - I don't get any errors (which I would expect).
I guess I could switch to NuGet but then the README says:

You do not need to manually install this NuGet package to your project if you are using .NET5 SDK or later. These analyzers are enabled by default for projects targeting .NET5 or later.

So, I think the documentation in the main README should be improved on how to get newer versions.

Closing comment (2021-03-09T16:29:45Z): After experiencing the issue reported in #4755 I noticed that you can force a newer version using <AnalysisLevel>5.0.3</AnalysisLevel>.
<AnalysisLevel>latest</AnalysisLevel> does not use the latest released version.