question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Completion crashes with InvalidCastException on CompletionList type

See original GitHub issue

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:

  1. create console project with ‘dotnet new console’
  2. start to write some c# code
  3. no code completion for c# extension 1.23.2 version
  4. 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:53 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
mbpcommented, Jul 22, 2021

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:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
  </dependentAssembly>
</assemblyBinding>

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.

2reactions
JoeRobichcommented, Jul 12, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio crash with System.InvalidCastException at ...
It looks like the crash is caused, because Visual Studio loads assemblies from our project into it's app domain. Our code then crashes...
Read more >
dbForge Studio for SQL Server History - Devart
Fixed incorrect script generation for table-based types in specific environments ... Added support for new functions in the Completion List, Quick Info, ...
Read more >
C# GUI keeps crashing due to System.InvalidCastException ...
I'm trying to write my own GUI for a Program in C#, which translate Morsecode to text. My IDE doesn't show any errors...
Read more >
Changes in Oxygene 4.0 - RemObjects
39141: Compiler fails when referenced types are duplicates ... 38439: Selecting an ampersand escaped member from the auto-complete list always adds a new ......
Read more >
InvalidCastException Class (System) - Microsoft Learn
NET Framework supports automatic conversion from derived types to their base ... An InvalidCastException exception is caused by developer error and should ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found