dotnet / project-system

The .NET Project System for Visual Studio
MIT License
968 stars 386 forks source link

Evaluation error leading to assertion in language service #9339

Closed drewnoakes closed 10 months ago

drewnoakes commented 10 months ago

Reported by @lifengl internally.

Opening OrchardCore (as per perf test) causes internal exception:

Microsoft.Assumes.InternalErrorException
  HResult=0x80131500
  Message=Primary workspace unknown.
  Source=Microsoft.VisualStudio.Validation
  StackTrace:
   at Microsoft.Assumes.Fail(String message)
   at Microsoft.VisualStudio.ProjectSystem.LanguageServices.LanguageServiceHost.<GetPrimaryWorkspaceAsync>d__21.MoveNext() in Microsoft.VisualStudio.ProjectSystem.LanguageServices\LanguageServiceHost.cs:line 206
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.LanguageServices.LanguageServiceHost.<WriteAsync>d__20`1.MoveNext() in Microsoft.VisualStudio.ProjectSystem.LanguageServices\LanguageServiceHost.cs:line 199
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.VS.Build.LanguageServiceErrorListProvider.<AddMessageCoreAsync>d__7.MoveNext() in Microsoft.VisualStudio.ProjectSystem.VS.Build\LanguageServiceErrorListProvider.cs:line 157
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Build.VsProjectBuildErrorListPublishService.<AddMessagesAsync>d__32.MoveNext() in C:\extra\CPS\src\Microsoft.VisualStudio.ProjectSystem.VS.Implementation\Build\VsProjectBuildErrorListPublishService.cs:line 295
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Build.VsProjectBuildErrorListPublishService.<ProcessQueueAsync>d__31.MoveNext() in C:\extra\CPS\src\Microsoft.VisualStudio.ProjectSystem.VS.Implementation\Build\VsProjectBuildErrorListPublishService.cs:line 257
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

Comment from Lifeng:

I guess this happens when there is a warning/error message during project evaluation. We will go through the code to deduplicate errors with Roslyn. But during project evaluation time, the Roslyn workspace hasn't been setup, so it ran into Workspace Unknown exception.

I wonder this filtering can be skipped during the evaluation time. We only need deduplication for real build?

It seems that if evaluation fails we can defer this code path (until if recovers in future).

drewnoakes commented 10 months ago

To repro this, checkout OrchardCore at ec2154ae099913ee81751f30c4f7660952fe63c9 then open/close the solution repeatedly until it's hit. A gold bar will be presented. It's not a 100% repro, but should only take a few cycles to see it.

drewnoakes commented 10 months ago

Also reported as https://developercommunity.visualstudio.com/t/Visual-Studio-issues-after-upgrade-yeste/10489672 (ticket AB#1900113, bug AB#1907473)

drewnoakes commented 10 months ago

Also bug AB#1872265