dotnet/vscode-csharp

Omnisharp server crashes on start

AlexTaran opened this issue · 6 comments

OS: Linux mint 20.1

Environment data

Checking dotnet version:

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.202
 Commit:    f8a55617d2

Runtime Environment:
 OS Name:     linuxmint
 OS Version:  20.1
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.202/

Host (useful for support):
  Version: 6.0.4
  Commit:  be98e88c76

.NET SDKs installed:
  6.0.202 [/usr/share/dotnet/sdk]

C# extension version: 1.24.4
VSCode version: 1.66.2

Opening VSCode, but it show the console with error:

OmniSharp log


Starting OmniSharp server at 4/22/2022, 3:27:25 PM
    Target: /home/alex/Documents/PROJECTS/Unity/TestMobile

OmniSharp server started.
    Path: /home/alex/.vscode/extensions/ms-dotnettools.csharp-1.24.4-linux-x64/.omnisharp/1.38.3-beta.67/run
    PID: 39792

System.TypeInitializationException: The type initializer for 'System.ComponentModel.TypeDescriptor' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
  at Interop+Sys..cctor () [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
   --- End of inner exception stack trace ---
  at Interop.GetRandomBytes (System.Byte* buffer, System.Int32 length) [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
  at System.Guid.NewGuid () [0x00000] in <533173d24dae460899d2b10975534bb0>:0 
  at System.ComponentModel.TypeDescriptor..cctor () [0x00034] in <9c6e2cb7ddd8473fa420642ddcf7ce48>:0 
   --- End of inner exception stack trace ---
  at OmniSharp.Internal.CommandOptionExtensions.GetValueOrDefault[T] (McMaster.Extensions.CommandLineUtils.CommandOption opt, T defaultValue) [0x00008] in <05a42112a1ea4f13b44c07c2ac51d933>:0 
  at OmniSharp.Stdio.StdioCommandLineApplication.get_Encoding () [0x00000] in <2c9765c70c4c4a338a1d3d785fb354b9>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_1.<Main>b__1 () [0x00000] in <ba882baba17b4f6e9ec23ff1f89a40fb>:0 
  at OmniSharp.CommandLineApplication+<>c__DisplayClass12_0.<OnExecute>b__0 () [0x0000b] in <05a42112a1ea4f13b44c07c2ac51d933>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication+<>c__DisplayClass146_0.<OnExecute>b__0 (System.Threading.CancellationToken _) [0x00000] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync (System.String[] args, System.Threading.CancellationToken cancellationToken) [0x000bf] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute (System.String[] args) [0x00016] in <abe0fc6797a94a73931eea5cecaffd78>:0 
  at OmniSharp.CommandLineApplication.Execute (System.String[] args) [0x00081] in <05a42112a1ea4f13b44c07c2ac51d933>:0 
  at OmniSharp.Stdio.Driver.Program+<>c__DisplayClass0_0.<Main>b__0 () [0x00028] in <ba882baba17b4f6e9ec23ff1f89a40fb>:0 
  at OmniSharp.HostHelpers.Start (System.Func`1[TResult] action) [0x0001c] in <05a42112a1ea4f13b44c07c2ac51d933>:0 
[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

Steps to reproduce

  1. Installed c# extension for vs code
  2. Installed mono like here: https://www.mono-project.com/download/stable/ (for latest ubuntu).

Expected behavior

C# autocomplete works in VScode

Actual behavior

See error above

Mono stable is over 1 year old and quite outdated, you should try with preview Mono https://www.mono-project.com/download/preview/

Thanks, tried "preview", but error is the same :(

I have the exact same issue. Running MAC OS 12.2.1 and the server was crashing when running omnisharp 1.38.3-beta.67 or 1.38.3-beta.69. Looking into the folder ~/.vscode/extensions/ms-dotnettools.csharp-1.24.4-darwin-x64/.omnisharp/ i found omnisharp version 1.38.2. Running this version from the terminal window worked. I changed the omnisharp path in VSCODE to the working version as a workaround. "omnisharp.path": "/Users/xxx/.vscode/extensions/ms-dotnettools.csharp-1.24.4-darwin-x64/.omnisharp/1.38.2/run" where xxx is the user folder.

I have the exact same issue. Running MAC OS 12.2.1 and I get this error in the Omnisharp Output window whenever VS Code loads up or I run the command to 'Restart Omnisharp'.

OmniSharp server started.
    Path: /Users/dirk/.vscode/extensions/ms-dotnettools.csharp-1.24.4-darwin-x64/.omnisharp/1.38.3-beta.78/run
    PID: 73743

System.TypeInitializationException: The type initializer for 'System.ComponentModel.TypeDescriptor' threw an exception. ---> System.TypeInitializationException: 
The type initializer for 'Sys' threw an exception. ---> System.DllNotFoundException: System.Native assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) Interop+Sys.LChflagsCanSetHiddenFlag()
  at Interop+Sys..cctor () [0x00000] in <0e2013ab6b944e008349d8dcd759ab4d>:0 
   --- End of inner exception stack trace ---
  at Interop.GetRandomBytes (System.Byte* buffer, System.Int32 length) [0x00000] in <0e2013ab6b944e008349d8dcd759ab4d>:0 
  at System.Guid.NewGuid () [0x00000] in <0e2013ab6b944e008349d8dcd759ab4d>:0 
  at System.ComponentModel.TypeDescriptor..cctor () [0x00034] in <81c889a3fdaf408aacac8a870695982b>:0 
   --- End of inner exception stack trace ---

I would say that Omnisharp has broken itself from one of its own update around 2 months ago. I've been hoping that the Omnisharp team would release a fix in one of the subsequent updates as this is quite a show stopper but the error still persists. It means that I need to use Visual Studio to write C# code.

Thank you so much for the fix.
Is it possible you can give some general guidance about the best practice for mono - I believe that Omnisharp and dotnet is the only reason I have mono installed, so should I uninstall the global mono, or just use a local version of it. I don't know enough about it to know what is best. Clearly this has evolved a bit over the years as to which version used and a lot of updating goes on behind the scenes. Thanks. (P.S. I usually update mono with 'brew install mono mono-libgdiplus').

Notice that the error is on the beta version of OmniSharp server - 1.38.3-beta.78. It is there, because you must have the setting "omnisharp.path":"latest" enabled, which opts you into the latest build from master, which can be very unstable (as demonstrated by this particular bug). By removing this setting completely, you go back to the OmniSharp server bundled with the extension which should work fine.

Going forward as described in the announcement #5120 the recommended approach is to:

  • set "omnisharp.useModernNet":true (will become the default soon) and install .NET 6 SDK. This will give you the most modern, stable and performant OmniSharp variant, built with .NET 6 (including native arm64 support). It supports .NET Core and newer frameworks development, but not (the "old") .NET Framework which is used e.g. by Unity. If you do not care about .NET Framework, this is the variant to use and there is no need to have Mono at all.
  • for Unity development and other "old" .NET Framework, set "omnisharp.useModernNet":false (and for the time being "omnisharp.useGlobalMono":"always", though that setting will become implicit in the fututre) and make sure the latest preview Mono is globally installed.