dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.97k stars 4.03k forks source link

VS error list often populates with warnings despite suppression by .editorconfig #49718

Open AArnott opened 3 years ago

AArnott commented 3 years ago

Version Used: 16.9 preview 3 (30730.13.main)

Steps to Reproduce:

git clone https://github.com/microsoft/CsWin32 --recursive
cd CsWin32
git checkout f963756f59f348b944a9e41884654e17a9bcdc74
.\Microsoft.Windows.Sdk.PInvoke.CSharp.sln

Open some of the source files in the test projects, or src\ScrapeDocs\Program.cs

Expected Behavior:

No errors or warnings in the error list. This matches dotnet build behavior which shows no errors/warnings.

Actual Behavior:

VS sometimes shows dozens of warnings, although their codes are suppressed in .editorconfig files found either in the project directory or a directory above.

mavasani commented 3 years ago

@AArnott Above steps seem to cause bunch of issues:

  1. Analyzer load failures in IDE as the analyzer assemblies could not be loaded:
Severity    Code    Description Project File    Line    Column  Category    Source  Suppression State
Warning CS8034  Unable to load Analyzer assembly c:\temp\CsWin32-main\CsWin32-main\bin\Microsoft.Windows.Sdk.PInvoke.CSharp\Debug\netstandard2.0\YamlDotNet.dll: Could not find file 'c:\temp\CsWin32-main\CsWin32-main\bin\Microsoft.Windows.Sdk.PInvoke.CSharp\Debug\netstandard2.0\YamlDotNet.dll'.  GenerationSandbox.Tests (net5.0)        1   1   Roslyn.HostError    IntelliSense    Active
  1. Build failure from command line:
c:\temp\CsWin32-main\CsWin32-main>msbuild /v:m
Microsoft (R) Build Engine version 16.9.0-preview-20570-04+b04541221 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs'. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs'. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
C:\Users\mavasani\.nuget\packages\microsoft.sourcelink.common\1.0.0\build\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
  ScrapeDocs -> c:\temp\CsWin32-main\CsWin32-main\bin\ScrapeDocs\Debug\net5.0\ScrapeDocs.dll
C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp'. [c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.csproj]
  Regenerating c:\temp\CsWin32-main\CsWin32-main\obj\Debug\apidocs.yml. This may take a few minutes...
  Enumerating documents to be parsed...
  Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path 'c:\temp\CsWin32-main\CsWin32-main\ext\sdk-api\sdk-api-src\content'.
     at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
     at System.IO.Enumeration.FileSystemEnumerator`1.Init()
     at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
     at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
     at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
     at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
     at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
     at ScrapeDocs.Program.Worker(CancellationToken cancellationToken) in c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\Program.cs:line 81
     at ScrapeDocs.Program.Main(String[] args) in c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\Program.cs:line 60
c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.targets(13,5): error MSB3073: The command "dotnet c:\temp\CsWin32-main\CsWin32-main\bin\ScrapeDocs\Debug\net5.0\ScrapeDocs.dll ../../ext/sdk-api/sdk-api-src/content ../../obj/Debug/apidocs.yml" exited with code -532462766. [c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.csproj]

Build FAILED.

C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs'. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(47,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs'. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
C:\Users\mavasani\.nuget\packages\microsoft.sourcelink.common\1.0.0\build\Microsoft.SourceLink.Common.targets(52,5): warning : Source control information is not available - the generated source link is empty. [c:\temp\CsWin32-main\CsWin32-main\src\ScrapeDocs\ScrapeDocs.csproj]
C:\Users\mavasani\.nuget\packages\microsoft.build.tasks.git\1.0.0\build\Microsoft.Build.Tasks.Git.targets(24,5): warning : Unable to locate repository with working directory that contains directory 'c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp'. [c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.csproj]
c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.targets(13,5): error MSB3073: The command "dotnet c:\temp\CsWin32-main\CsWin32-main\bin\ScrapeDocs\Debug\net5.0\ScrapeDocs.dll ../../ext/sdk-api/sdk-api-src/content ../../obj/Debug/apidocs.yml" exited with code -532462766. [c:\temp\CsWin32-main\CsWin32-main\src\Microsoft.Windows.Sdk.PInvoke.CSharp\Microsoft.Windows.Sdk.PInvoke.CSharp.csproj]
    4 Warning(s)
    1 Error(s)
AArnott commented 3 years ago

Ah, sorry. I left the --recursive switch out of the repro steps. Can you try again?

mavasani commented 3 years ago

Thanks. I can now enlist and build the repo, but still am not able to repro the core issue. Opening various files OR turning on full solution analysis still doesn't show any warnings in error list. I am on build Version 16.9.0 Preview 3.0 [30730.13.main]. I'll keep trying, but looking at your comment VS sometimes shows dozens of warnings, it seems like this might be some race condition in the way editorconfig documents are detected and added to the workspace. Also tagging @jasonmalinowski

AArnott commented 3 years ago

Ya, it's not consistent for me either. In fact, it usually works. But when it doesn't, it's intensely annoying since my error list fills with hundreds of warnings at times.

mavasani commented 3 years ago

@AArnott When it repros for you, does it happen the first time you open the solution or the warnings start popping up midway through your VS session? If it is the former, this is very likely a recent race condition introduced when we changed to a different model in Roslyn compiler and IDE to populate and store the editorconfig options using a SyntaxTreeOptionsProvider.

AArnott commented 3 years ago

I think it happens at the start of the session.

mavasani commented 3 years ago

Moving to @jasonmalinowski - this is likely a race condition from recent changes related to SyntaxTreeOptionsProvider that leads to editorconfig being intermittently ignored in IDE. Not sure what is good way to repro/investigate this though...

AArnott commented 3 years ago

Tip: this definitely happens mid-session. It happened twice this afternoon, both times immediately after updating global.json from 3.1.302 to 5.0.100 and at the same time adjusting TargetFrameworks to drop netcoreapp2.1 and add net5.0.

These were the changes, made in memory all at once in VS and applied with Save All.

onyxmaster commented 3 years ago

The #49597 you closed as a duplicate has a repo and a video that shows repro steps. On my machine following these steps has a 100% repro rate, did you try those steps?

jasonmalinowski commented 3 years ago

So I got @AArnott's repro to reproduce...once. @onyxmaster no luck with your repro unfortunately.

For anybody who hits this next: if you have the Project System Tools extension installed, it adds a command Tools > Log Roslyn Workspace Structure which will create a log file that might be useful here.

onyxmaster commented 3 years ago

before.zip after.zip

AArnott commented 3 years ago

I hit it today too: manyerrors.zip

WernerMairl commented 3 years ago

using VS 2019 16.10 i see the same behavior: analyzer ignores .editorconfig for "intellisense"

will see if i can provide logs too...

WernerMairl commented 3 years ago

Strange: installed the Tool mentioned here => Vs Restart => issue resolved 🙈 ... no problems (2 days until now)

jasonmalinowski commented 3 years ago

This report was similar to https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1307480 where we were unable to reproduce.

AArnott commented 3 years ago

I've been hitting this again lately too. It's not often, and closing/re-opening the solution seems to solve it.

onyxmaster commented 3 years ago

It's present in VS2022 preview 3.1 also. Reopening solution indeed solves the issue, but I prefer not to reload it because of this: image

kernst123 commented 2 years ago

I can also duplicate this problem. I will try installing the Project System Tools to see if I can still get it to happen.

daveaglick commented 1 year ago

I think I'm seeing this same problem...though I'm not using an IDE and see it even with a plain old console dotnet build call (but that would probably make sense if it's a race condition inside Roslyn).

What's interesting is that the number of errors seems to change, so I suspect the .editorconfig is being intermittently ignored on a per-project basis. Here's two dotnet build calls seconds apart for a large multi-project solution, one right after the other with a dotnet clean before each one.

image

image

Repeating this exercise continues to report varying numbers of errors (until eventually I get a good build...hopefully).

CyrusNajmabadi commented 1 year ago

@daveaglick that would be a separate issue. Can you file a new issue? Thanks!

daveaglick commented 1 year ago

Sure thing - if it's not related, let me try to gather some more information first so I'm giving you all a clear picture. Always possible (likely?) that I'm holding it wrong in the first place.