Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer dependencies showing as unresolved full paths #5418

Closed
drewnoakes opened this issue Sep 3, 2019 · 18 comments · Fixed by #5830
Closed

Analyzer dependencies showing as unresolved full paths #5418

drewnoakes opened this issue Sep 3, 2019 · 18 comments · Fixed by #5830
Assignees
Labels
Bug This is a functional issue in already written code. Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references Regression Regressions from a previous (typically public) build or release. Triage-Approved Reviewed and prioritized
Milestone

Comments

@drewnoakes
Copy link
Member

drewnoakes commented Sep 3, 2019

Steps to reproduce:

  1. Create a new .NET Core Console App
  2. Add a package reference to xunit.analyzers
  3. Build the solution
  4. Close the solution
  5. Re-open the solution
  6. Expand the project's dependencies node
  7. Notice there is no Analyzers node
  8. Modify whitespace in the project file and save it (triggering a design-time build)
  9. Notice an Analyzers node appears with unresolved child, which is a full path rather than the analyzer's name
    image
  10. Close and reopen the solution and the analyzers appear correctly
  11. Modify the project file again (stays resolved)
  12. Close and re-open the solution (stays resolved)
  13. Build from VS then close/re-open solution and notice Analyzers node is missing again

Open questions:

  • Why is the Analyzers node not initially present? This seems to happen if the build before opening the solution happened within VS.
  • Why are analyzers appearing as paths and in unresolved state?
@drewnoakes drewnoakes added Bug This is a functional issue in already written code. Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references labels Sep 3, 2019
@drewnoakes drewnoakes added this to the 16.x milestone Sep 3, 2019
@drewnoakes drewnoakes self-assigned this Sep 3, 2019
@drewnoakes drewnoakes added the Regression Regressions from a previous (typically public) build or release. label Sep 5, 2019
@drewnoakes drewnoakes modified the milestones: 16.x, 16.4 Sep 5, 2019
@drewnoakes
Copy link
Member Author

As part of fixing this, add coverage of analyzers to the integration tests.

@drewnoakes drewnoakes added this to To do in Sprint 158 via automation Sep 5, 2019
@drewnoakes
Copy link
Member Author

drewnoakes commented Sep 5, 2019

Some notes to capture findings of investigations.

  • It doesn't appear to vary based on SDK version
  • It does reproduce in 16.2.3
  • It does NOT reproduce in 15.9.15
  • It seems related to a restored cache of DTB data

(EDIT removed incorrect git bisect log as I'd misidentified the good commit)

@drewnoakes drewnoakes added this to To do in Sprint 159 via automation Sep 9, 2019
@drewnoakes drewnoakes removed this from To do in Sprint 158 Sep 9, 2019
@DamianEdwards
Copy link
Member

FYI still repros in 16.3.1 when working with ASP.NET Core projects:
image

@drewnoakes drewnoakes added this to To do in Sprint 160 via automation Oct 1, 2019
@drewnoakes drewnoakes removed this from To do in Sprint 159 Oct 1, 2019
@drewnoakes
Copy link
Member Author

This is potentially caused by metadata filtering in the DTB cache for task items. From the (internal) ProjectServices repo:

MSBuild throws exceptions when we access path related properties on non-path items.
We try to prevent running into such frequent exceptions by detecting some common invalid path patterns.

This filtering applies when writing the cache, which fits with the above repro steps. My current hunch is that data needed by the Analyzers node is being filtered out by the cache, but this needs further investigation.

@drewnoakes
Copy link
Member Author

drewnoakes commented Jan 6, 2020

Paths are shown for unresolved analyzer references:

https://github.com/dotnet/roslyn/blob/ef4e36fd040f77ba5103434101138598f4c6233f/src/VisualStudio/Core/SolutionExplorerShim/AnalyzerItem/AnalyzerItem.cs#L83-L93

EDIT: This is a red herring. Roslyn creates the full Analyzers node for legacy projects, but for this project system it only populates diagnostic items. We have similar logic however:

Caption = resolved
? System.IO.Path.GetFileNameWithoutExtension(path)
: path;

@drewnoakes
Copy link
Member Author

drewnoakes commented Jan 10, 2020

This can be reproduced more easily by:

  1. New ASP.NET Core Web Application (empty)
  2. Close solution
  3. Reopen solution

Deleting the .dtbcache file in the .vs folder between steps 2 and 3 fixes the problem, so the DTB caching in ProjectServices is looking like the culprit here.


EDIT The above worked for me five times in a row, but no longer does. It doesn't seem that deterministic. Running VS in the debugger makes it fail more often. Right now I'm Ctrl+F5'ing and can't repro it at all.

@DamianEdwards
Copy link
Member

@drewnoakes really appreciate the persistence on this 👍

@ttaylor29
Copy link

@drewnoakes post helped me out! Thank you!

@drewnoakes drewnoakes added this to To do in Sprint 165 via automation Jan 17, 2020
@drewnoakes
Copy link
Member Author

Getting closer. This appears to be a race condition. If the VS instance is 'warm' (has previously had a solution open) then the problem triggers. The presence of the DTB cache factors in to the sequence of events, as it's much faster to read the cache than do a DTB. It also explains why using the debugger hasn't been helpful, as that changes timing too. I'm going to add some tracing to dig deeper.

@drewnoakes drewnoakes moved this from To do to In progress in Sprint 165 Jan 24, 2020
Sprint 165 automation moved this from In progress to Done Jan 27, 2020
@drewnoakes
Copy link
Member Author

This has been fixed and will be released in 16.5.

@AssafAuo
Copy link

could be but 16.5 is not out yet

@keserwan
Copy link

This has been fixed and will be released in 16.5.

I just updated Visual studio to 16.4.4 and the issue was resolved.
The reference is fixed and no more yellow triangle.
Thanks.

@drewnoakes
Copy link
Member Author

@keserwan glad it's working for you, but the fix is not present in that build. It will be in 16.5, and most likely in a preview.

@arphox
Copy link

arphox commented Mar 2, 2020

I fixed this error by deleting the solution's .vs folder along with all bin and obj folders in all subprojects. All of these of course while VS was not running.

@oboro-san
Copy link

@arphox Thanks alot. Your suggestion worked for me

@davkean
Copy link
Member

davkean commented Mar 13, 2020

That will work until the next reload of the solution, the fix is in 16.5.

@yunsong0922
Copy link

That's also works for me. Thanks @arphox

@walterpg
Copy link

Hi, We've found another manifestation of this issue in our project extension.

When the project loads, we see a an "empty" (but not null) project change (presumably an inconsequential DTB?). In the same update there is an evaluation change, which is the resolution of the analyzer files. Since the project change is not null, the evaluation change is not handled, and so we see the dreaded warning triangles.

We do not have a simple replication, but we do have a simple one-line fix in DependenciesRuleHandlerBase that "works for us". We can produce a pull request if desired.

walterpg added a commit to asnarnd/project-system that referenced this issue Sep 23, 2022
Basically, don't let empty project updates eclipse potential
evaluation updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a functional issue in already written code. Feature-Dependency-Node "Dependencies" node in Solution Explorer that display project, binary & package references Regression Regressions from a previous (typically public) build or release. Triage-Approved Reviewed and prioritized
Projects
No open projects
Sprint 160
  
In progress
Sprint 165
  
Done
Development

Successfully merging a pull request may close this issue.

10 participants