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.89k stars 4.01k forks source link

We're using the wrong simplifier options in a cross-language case #60941

Open jasonmalinowski opened 2 years ago

jasonmalinowski commented 2 years ago

Hit this in Version 17.3.0 Preview 1.0 [32418.120.main]

System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Simplification.VisualBasicSimplifierOptions' to type 'Microsoft.CodeAnalysis.CSharp.Simplification.CSharpSimplifierOptions'. 
at Microsoft.CodeAnalysis.CSharp.Simplification.CSharpSimplificationService.GetSimplifierOptions(AnalyzerConfigOptions options, SimplifierOptions fallbackOptions) 
at Microsoft.CodeAnalysis.Simplification.SimplifierOptions.<FromDocumentAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.CodeAnalysis.MetadataAsSource.DecompilationMetadataAsSourceFileProvider.<GetGeneratedFileAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceFileService.<GetGeneratedFileAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.LanguageServices.Implementation.VisualStudioSymbolNavigationService.<GetNavigableLocationForMetadataAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.LanguageServices.Implementation.VisualStudioSymbolNavigationService.<GetNavigableLocationAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.CodeAnalysis.FindUsages.DefinitionItem.DefaultDefinitionItem.<GetNavigableLocationAsync>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at Microsoft.CodeAnalysis.GoToDefinition.AbstractGoToSymbolService.<GetSymbolsAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.CodeAnalysis.Editor.NavigableSymbols.NavigableSymbolService.NavigableSymbolSource.<GetNavigableSymbolAsync>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Language.Intellisense.Implementation.GoToDefMouseHandler.<QueryNavigableSymbolAsync>d__34.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Language.Intellisense.Implementation.GoToDefMouseHandler.<SetMouseCursorAndNavigableSpanHelperAsync>d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at Microsoft.VisualStudio.Language.Intellisense.Implementation.GoToDefMouseHandler.<SetMouseCursorAndNavigableSpanHelperAsync>d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Language.Intellisense.Implementation.GoToDefMouseHandler.<>c__DisplayClass31_0.<<SetMouseCursorAndNavigableSpanAsync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Language.Intellisense.Implementation.GoToDefMouseHandler.<SetMouseCursorAndNavigableSpanAsync>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.<CallExtensionPointAsync>d__37.MoveNext()
jasonmalinowski commented 2 years ago

@tmat or @davidwengier not sure if this might be a recent regression?

tmat commented 2 years ago

Will take a look. Have repro by chance?

jasonmalinowski commented 2 years ago

@tmat: not exactly but I hit this while writing https://github.com/dotnet/roslyn/pull/60870. I'm guessing my editing in FileCodeModelTests.vb and where it references types in C# code might have been the problem?

jasonmalinowski commented 2 years ago

Oh, I guess though if it's running decompilation, maybe it was me holding Ctrl and hovering over something from metadata?