vscode-csharp: Completion crashes with InvalidCastException on CompletionList type
Extension version: 1.23.2 VS Code version: Code 1.49.2 (e5e9e69aed6e1984f7499b7af85b3d05f9a6883a, 2020-09-24T16:29:41.983Z) OS version: Windows_NT x64 10.0.19041
Steps to reproduce problem:
- create console project with ‘dotnet new console’
- start to write some c# code
- no code completion for c# extension 1.23.2 version
- after downgrading c# extension to 1.23.1 code completion works OK
System.InvalidCastException: Nie można zrzutować
[A]System.Threading.Tasks.Task`1[System.ValueTuple`2[Microsoft.CodeAnalysis.Completion.CompletionList,System.Boolean]] na
[B]System.Threading.Tasks.Task`1[System.ValueTuple`2[Microsoft.CodeAnalysis.Completion.CompletionList,System.Boolean]].
Typ A pochodzi od mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 w kontekście LoadNeither w lokalizacji C:\\\\WINDOWS\\\\Microsoft.Net\\\\assembly\\\\GAC_64\\\\mscorlib\\\\v4.0_4.0.0.0__b77a5c561934e089\\\\mscorlib.dll.
Typ B pochodzi od mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 w kontekście LoadNeither w lokalizacji C:\\\\WINDOWS\\\\Microsoft.Net\\\\assembly\\\\GAC_64\\\\mscorlib\\\\v4.0_4.0.0.0__b77a5c561934e089\\\\mscorlib.dll.\\r\\n
w OmniSharp.Roslyn.CSharp.Services.Intellisense.CompletionItemExtensions.GetCompletionsInternalAsync(CompletionService completionService, Document document, Int32 caretPosition, CompletionTrigger trigger, ImmutableHashSet`1 roles, OptionSet options, CancellationToken cancellationToken) w D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Intellisense\\\\CompletionItemExtensions.cs:wiersz 64\\r\\n w OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService.<Handle>d__7.MoveNext() w D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Roslyn.CSharp\\\\Services\\\\Completion\\\\CompletionService.cs:wiersz 120\\r\\n--- Koniec śladu stosu z poprzedniej lokalizacji, w której wystąpił wyjątek ---\\r\\n w System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n w System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n w OmniSharp.Endpoint.EndpointHandler`2.<GetFirstNotEmptyResponseFromHandlers>d__19.MoveNext()\\r\\n--- Koniec śladu stosu z poprzedniej lokalizacji, w której wystąpił wyjątek ---\\r\\n w System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n w System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n w OmniSharp.Endpoint.EndpointHandler`2.<HandleRequestForLanguage>d__20.MoveNext() w D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:wiersz 230\\r\\n--- Koniec śladu stosu z poprzedniej lokalizacji, w której wystąpił wyjątek ---\\r\\n w System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n w System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n w OmniSharp.Endpoint.EndpointHandler`2.<Process>d__16.MoveNext() w D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:wiersz 131\\r\\n--- Koniec śladu stosu z poprzedniej lokalizacji, w której wystąpił wyjątek ---\\r\\n w System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n w System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n w OmniSharp.Stdio.Host.<HandleRequest>d__13.MoveNext() w D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Stdio\\\\Host.cs:wiersz 215
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 53 (17 by maintainers)
Ok, I found something.
If I modify file
OmniSharp.exe.config
located in.vscode\extensions\ms-dotnettools.csharp-1.23.13\.omnisharp\1.37.12
and remove this section:Then the exception goes away, and code completion starts working!
I don’t know why this binding redirect is added on compilation, however I discovered McMaster.Extensions.CommandLineUtils/2.2.4 was depending on 4.4.0 of System.ValueTuple while omnisharp-roslyn depends on 4.5.0. Newer versions of McMaster.Extensions.CommandLineUtils depend on 4.5.0. When I upgraded the dependency, the binding redirect was no longer added to
OmniSharp.exe.config
I have made a pull request in
omnisharp-roslyn
to upgrade the dependency.Multiple loading of the OmniSharp.MSBuild assembly should be resolved with the following two changes being merged https://github.com/OmniSharp/omnisharp-vscode/pull/4642 & https://github.com/OmniSharp/omnisharp-vscode/pull/4643. We expect to have a pre-release build shortly that we will validate for publishing.
I tried debugging into OmniSharp.exe. I found that if I replace this line:
With these:
Then everything works. Of course this is not the right fix, but wanted to provide this info.
It is not clear to me why MissingMethodException on the tuple line, but I found old Roslyn issue (https://github.com/dotnet/roslyn/issues/22903) which shows a connection between ValueTuple and MissingMethodException.
I downgraded my ms-dotnettools.csharp extension to v1.23.1, which includes Omnisharp v1.37.0 to make IntelliSense (by this I mean method and property hints when I type a dot, parameter hints when I type a “(” do still work in later versions) work. I installed and tested all ms-dotnettools.csharp versions above v1.23.1 and in none of those versions does IntelliSense work for me.