dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

System.InvalidCastException: Specified cast is not valid. #3278

Closed mdmoura closed 5 years ago

mdmoura commented 5 years ago

Issue Description

When starting, or restarting, Omnisharp in Visual Studio Code I get the error: System.InvalidCastException: Specified cast is not valid.

OmniSharp log

Starting OmniSharp server at 9/13/2019, 12:05:54 PM Target: /Users/mdm/Project.Source/src/Api OmniSharp server started with Mono 5.18.1. Path: /Users/mdm/.vscode/extensions/ms-vscode.csharp-1.21.2/.omnisharp/1.32.19-beta.25/omnisharp/OmniSharp.exe PID: 1963 [info]: OmniSharp.Stdio.Host Starting OmniSharp on MacOS 10.14.6 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: Mono 15.0 - "/Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/15.0/bin" 2: StandAlone 15.0 - "/Users/mdm/.vscode/extensions/ms-vscode.csharp-1.21.2/.omnisharp/1.32.19-beta.25/omnisharp/.msbuild/Current/Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Mono 15.0 - "/Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/15.0/bin" CscToolPath = /Users/mdm/.vscode/extensions/ms-vscode.csharp-1.21.2/.omnisharp/1.32.19-beta.25/omnisharp/.msbuild/Current/Bin/Roslyn CscToolExe = csc.exe System.InvalidCastException: Specified cast is not valid. at Roslyn.Utilities.EventMap.GetRegistries_NoLock[TEventHandler] (System.String eventName) [0x0001b] in <889d2020dcce4567aad80a068551b1d4>:0 at Roslyn.Utilities.EventMap.AddEventHandler[TEventHandler] (System.String eventName, TEventHandler eventHandler) [0x00015] in <889d2020dcce4567aad80a068551b1d4>:0 at Microsoft.CodeAnalysis.Workspace.add_WorkspaceChanged (System.EventHandler`1[TEventArgs] value) [0x00000] in <889d2020dcce4567aad80a068551b1d4>:0 at Microsoft.AspNetCore.Razor.OmniSharpPlugin.PrecompiledRazorPageSuppressor..ctor (OmniSharp.OmniSharpWorkspace workspace) [0x0001b] in <8c6f4eb2e16d4051ba80a599aba81c54>:0 at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,System.Composition.Hosting.Core.LifetimeContext,System.Composition.Hosting.Core.CompositionOperation) at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate (System.Int32 sharingId, System.Composition.Hosting.Core.CompositionOperation operation, System.Composition.Hosting.Core.CompositeActivator creator) [0x000a8] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.TypedParts.ActivationFeatures.LifetimeFeature+<>c__DisplayClass1_0.b__0 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x00011] in <9aac21a4a3f24063b2b8b59143acddfc>:0 at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider+<>c__DisplayClass3_2`1[TElement].b__4 (System.Composition.Hosting.Core.ExportDescriptor e) [0x00006] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Linq.Enumerable+SelectArrayIterator`2[TSource,TResult].ToArray () [0x00012] in <28b7381f9e304c3eae9fa66907f89854>:0 at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <28b7381f9e304c3eae9fa66907f89854>:0 at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider+<>c__DisplayClass3_1`1[TElement].b__3 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x0002b] in <8e026c716fc84f38aae28085eaaee9fc>:0 at (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,System.Composition.Hosting.Core.LifetimeContext,System.Composition.Hosting.Core.CompositionOperation) at System.Composition.Hosting.Core.LifetimeContext.GetOrCreate (System.Int32 sharingId, System.Composition.Hosting.Core.CompositionOperation operation, System.Composition.Hosting.Core.CompositeActivator creator) [0x000a8] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.TypedParts.ActivationFeatures.LifetimeFeature+<>c__DisplayClass1_0.b__0 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x00011] in <9aac21a4a3f24063b2b8b59143acddfc>:0 at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider+<>c__DisplayClass3_2`1[TElement].b__4 (System.Composition.Hosting.Core.ExportDescriptor e) [0x00006] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Linq.Enumerable+SelectArrayIterator`2[TSource,TResult].ToArray () [0x00012] in <28b7381f9e304c3eae9fa66907f89854>:0 at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <28b7381f9e304c3eae9fa66907f89854>:0 at System.Composition.Hosting.Providers.ImportMany.ImportManyExportDescriptorProvider+<>c__DisplayClass3_1`1[TElement].b__3 (System.Composition.Hosting.Core.LifetimeContext c, System.Composition.Hosting.Core.CompositionOperation o) [0x0002b] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.Hosting.Core.CompositionOperation.Run (System.Composition.Hosting.Core.LifetimeContext outermostLifetimeContext, System.Composition.Hosting.Core.CompositeActivator compositionRootActivator) [0x0001c] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.Hosting.Core.LifetimeContext.TryGetExport (System.Composition.Hosting.Core.CompositionContract contract, System.Object& export) [0x0001d] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.Hosting.CompositionHost.TryGetExport (System.Composition.Hosting.Core.CompositionContract contract, System.Object& export) [0x00000] in <8e026c716fc84f38aae28085eaaee9fc>:0 at System.Composition.CompositionContext.GetExport (System.Composition.Hosting.Core.CompositionContract contract) [0x00000] in <12675e53c8854b48abd187539ce374db>:0 at System.Composition.CompositionContext.GetExports (System.Type exportType, System.String contractName) [0x00023] in <12675e53c8854b48abd187539ce374db>:0 at System.Composition.CompositionContext.GetExports[TExport] (System.String contractName) [0x00000] in <12675e53c8854b48abd187539ce374db>:0 at System.Composition.CompositionContext.GetExports[TExport] () [0x00000] in <12675e53c8854b48abd187539ce374db>:0 at OmniSharp.Stdio.Host.Initialize () [0x0001e] in <3cc12c7c00f344b08c42dfac73970669>:0 at OmniSharp.Stdio.Host..ctor (System.IO.TextReader input, OmniSharp.Services.ISharedTextWriter writer, OmniSharp.IOmniSharpEnvironment environment, System.IServiceProvider serviceProvider, OmniSharp.CompositionHostBuilder compositionHostBuilder, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Threading.CancellationTokenSource cancellationTokenSource) [0x00070] in <3cc12c7c00f344b08c42dfac73970669>:0 at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.
b__1 () [0x00138] in <0a1d4b17e42e41ff8dffd9ad6b26ea3a>:0 at OmniSharp.CommandLineApplication+<>c__DisplayClass11_0.b__0 () [0x0000b] in <26e431e77bba4574aea35bb4bb3374a8>:0 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00039] in <344a1e8cd6594b17b1e01f8df6ae8827>:0 at OmniSharp.CommandLineApplication.Execute (System.Collections.Generic.IEnumerable`1[T] args) [0x00042] in <26e431e77bba4574aea35bb4bb3374a8>:0 at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.
b__0 () [0x00028] in <0a1d4b17e42e41ff8dffd9ad6b26ea3a>:0 at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <26e431e77bba4574aea35bb4bb3374a8>:0 [ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

Environment information

VSCode version: 1.38.1 C# Extension: 1.21.2

Mono Information OmniSharp using global mono :5.18.1
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.2.401 Commit: 729b316c13 Runtime Environment: OS Name: Mac OS X OS Version: 10.14 OS Platform: Darwin RID: osx.10.14-x64 Base Path: /usr/local/share/dotnet/sdk/2.2.401/ Host (useful for support): Version: 2.2.6 Commit: 7dac9b1b51 .NET Core SDKs installed: 2.2.401 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |Angular2|johnpapa|8.1.1| |azure-account|ms-vscode|0.8.4| |csharp|ms-vscode|1.21.2| |typescript-hero|rbbit|3.0.0| |vscode-mjml|attilabuti|1.6.0| |vscode-yaml|redhat|0.5.2|;
filipw commented 5 years ago

this is a dupe of #3274 please see https://github.com/OmniSharp/omnisharp-vscode/issues/3274#issuecomment-530520009 or try installing the latest beta from https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.21.3-beta1

mdmoura commented 5 years ago

Thank you. I solved it by adding "latest" to "omnisharp.path".

I had a specific beta version I added sometime ago because of an existing bug.