dotnet/roslyn-analyzers

Code analysis violations differ depending on whether file is open in editor or not

vsfeedback opened this issue · 0 comments

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
Some code analysis false positives are shown in the error list, but when I open the offending files to investigate, they disappear.

I have observed this for IDE0079 - Remove unnecessary suppression for a while.

After a recent update of all dependencies, it also happened for CS8602 - Dereference of a possibly null reference. The problem here is that when the file is open, the analysis understands that Assert.That(MyNullable?.IsAwesome, Is.True); or Assert.That(MyNullable?.IsAwesome, Is.False); implies that MyNullable is not null afterwards, but when the file is closed, it doesnt.

Microsoft Visual Studio Professional 2022
Version 17.8.3
VisualStudio.17.Release/17.8.3+34330.188
Microsoft .NET Framework
Version 4.8.09037
Installed Version: Professional
C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!- ... ->
    <TargetFramework>net8.0</TargetFramework>
    <LangVersion>12</LangVersion>
    <Nullable>enable</Nullable>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <NoWarn />
    <AnalysisLevel>latest-all</AnalysisLevel>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <WarningsAsErrors>Nullable</WarningsAsErrors>
  </PropertyGroup>
  <PropertyGroup>
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
  </PropertyGroup>
  <ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
  </ItemGroup>
  <ItemGroup>
    <AdditionalFiles Include="BannedSymbols.txt" />
  </ItemGroup>
  <ItemGroup>
    <!- ... ->
    <PackageReference Include="CommunityToolkit.Common" Version="8.2.2" />
    <PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
    <!- ... ->
    <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
   <!- ... ->
    <PackageReference Include="NUnit.Analyzers" Version="4.2.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <!- ... ->
    <PackageReference Include="Roslynator.Analyzers" Version="4.12.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.12.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.12.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="SonarAnalyzer.CSharp" Version="9.30.0.95878">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <!- ... ->
  </ItemGroup>
  <!- ... ->
</Project>

Original Comments

Feedback Bot on 10/8/2024, 09:25 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 10/10/2024, 11:25 AM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.