vscode-csharp: OmniSharp crashing - I think there must have been some update causing this issue.

I think there must have been a bug in some of the recent updates causing the following issue. Since two days OmniSharp behaves very strange. It occurs randomly, but often. After I edit my code:

  1. Syntax highlighting gets broken, parts of the code stay in default color, sometimes even half a word stay highlighted correctly and the rest loses resets to default color.
  2. Problems panel lists many extra errors that are just a fiction. I have to run dotnet build in the terminal to find the true errors.

For example, I changed a declaration of a HashSet<Shape> to a List<Shape>. The following error appeared: The type or namespace name 'HistashSet<>' could not be found (are you missing a using directive or an assembly reference?) and it stays being shown even after half an hour. Some issue must have occurred while I was typing and the code is not re-analyzed anymore. Further fictitious errors occur everywhere I use the respective variable. The syntax highlighting around the edited spot is broken.

The previous example affected just a small portion of the code within just one file. Yesterday I managed to get several hundreds of fictious errors and whole files with over 1k lines all red. It’s impossible to work this way 😢

The following debug information contains also an exception that massively occurs in the OmniSharp log. It is an ArgumentOutOfRange at Microsoft.CodeAnalysis.Text.LinePosition..ctor (System.Int32 line, System.Int32 character) [0x00013] in <74e762f007514b0991a005183ec8dcb2>:0

Environment data

.NET Core SDK (reflecting any global.json):
 Version:   3.1.404
 Commit:    470f6754b3

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.404/

Host (useful for support):
  Version: 3.1.10
  Commit:  1721e39439

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

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

C# Extension version: 1.23.5

OmniSharp log

Starting OmniSharp server at 11/11/2020, 10:07:02 PM
    Target: xxx.sln

OmniSharp server started.
    Path: /home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/run
    PID: 7984

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on ubuntu 20.4 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "/home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "/home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin
            CscToolPath = /home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /home/xxx/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/xxx'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/xxx/xxx.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
...
[fail]: OmniSharp.Stdio.Host
        ************  Response ************ 
{
  "Request_seq": 15,
  "Command": "/v2/highlight",
  "Running": true,
  "Success": false,
  "Message": "\"System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.\\nParameter name: character\\n  at Microsoft.CodeAnalysis.Text.LinePosition..ctor (System.Int32 line, System.Int32 character) [0x00013] in <74e762f007514b0991a005183ec8dcb2>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.SemanticHighlight.SemanticHighlightService.Handle (OmniSharp.Models.SemanticHighlight.SemanticHighlightRequest request) [0x00146] in <8ca5e445b15640a0986680e5a0180b25>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request) [0x00099] in <9e06207949b04d41ac60c7c691c8ecbb>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <9e06207949b04d41ac60c7c691c8ecbb>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <9e06207949b04d41ac60c7c691c8ecbb>:0 \\n  at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000e7] in <add5f40a6e784fcca3e930b59965388b>:0 \"",
  "Body": null,
  "Seq": 121,
  "Type": "response"
}
[fail]: OmniSharp.Stdio.Host

//This exception repeats many many times.

Steps to reproduce

Unknown, happens randomly at code edits.

Expected behavior

Syntax highlighting should work and there should be no fictitious errors.

Actual behavior

Syntax highlighting broken and plenty of fictitious errors appear.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 22
  • Comments: 26 (1 by maintainers)

Most upvoted comments

Same here: Received response for /v2/getcodeactions but could not find request.

These bugs are very frustrating. Omnisharp is slowing becoming omnishit.

I’ve found a possible cause - the project i was working on was not in the sln file, vscode doesn’t care so much about sln, but when there is one, and it’s missing a project, omnisharp appears to be busted.

Can confirm – we’ve run into Omnisharp having stability problems to the point of our entire team having to restart omnisharp/VS code multiple times a day, it’s really rough. I finally started Googling errors and landed here, ~30 days ago would probably be a fair estimate of when it started too (though we’ve always had little struggles with Omnisharp suddenly not working and needing a restart.

FWIW: I just threw my hands up and rolled back to 1.23.0 and it’s at least working so far.

Falling in with @isolin here. With 1.23.6 all above mentioned problems still occur and in some ways have actually gotten worse for me.

I now regularly have to use the shortcut to force-reload the VSCode window to get the extension to pick up code changes and re-evaluate conditions. It’s a downright mess and I’ve reverted back to 1.23.2 - which, although it has more issues with e.g. Razor templates, atleast is sane for my common use cases.

Ever since 1.23.3 everything regarding error reporting and intellisense seems to have gone down the shitter with those parts being refactored. At this point, if I were running this project I’d be inclined to back it all out and leave it on another branch to stew for another half a year until all the bugs and issues have been squashed. Beause currently, it flat out is not production-ready.

@pontus-eliason Any update on this?

I’ve tried with the latest public release 1.23.9 and it’s still a long list of errors galore; editor content and supplied autocompletion falling out of sync; etc. 1.23.2 - which is afaik the last release from before the pipeline that connects Omnisharp to the editor content was moved over to a new implementation based on newer interfaces in VSCode - is still the last (semi-)properly working release for me. It still has weird errors and its state still loses sync, but it’s a whooo----le lot more stable than everything that came after.

Also meant to link to a few possible sibling issues, these are all big maybes especially since it’s a mixture of OS’s, although I’ve seen the below issues periodically:

Omnisharp does not detect fixed code until restart or manual build for certain error types #4185 Omnisharp freeze, not working and high cpu usage #4017 Intellisense not working. #4047 Intellisense inconsistent (doesn’t always auto start) #4342 “Go to type definition” and other navigations not working #4251

It’s definitely been a headache for a long time for me, but I will say… thank you to all of you who are working on this, still my favorite editor. 👍

I’ve been having the same for a long time, everything above as described although I’m on mac and also reverting versions hasn’t helped. I wish I could even say which versions cause which errors but it’s been a crapshoot and reloading the window only works sometimes. And by sometimes I mean sometimes it crashes immediately and other times I get an assortment of errors after making code changes and it ultimately locks up.

Just to flush out a few more details from my end:

Preliminary Steps Taken: . Disabled/Uninstalled all extensions . Uninstalled/Reinstalled VSC 1.52.1 multiple times . Tried installing each version of the extension from 1.23.8 down to 1.21.18 . Uninstalled mono globally . Set "omnisharp.useGlobalMono": "never" . Verified in omnisharp logs that it’s using its internal version of msbuild 16.8.0

To no avail.

In the case that omnisharp doesn’t outright crash, an easy repro to bring it down is copy and paste a method (so that it’s a duplicate), then add and remove a letter to the end of the method name (causing it to stop being a duplicate, then making it a duplicate again) multiple times. With a log level of trace, adding/deleting a single letter twice in ~5 seconds dumps ~7,500 lines of logs, spikes the cpu to ~200% and the process consumes ~1GB, usually with either

ERR Problem invoking 'GetCodeActions' on OmniSharp server: Error: Pending request cancelled: /v2/getcodeactions

or this one

ERR Problem invoking 'GetCodeActions' on OmniSharp server: "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.\nParameter name: index\n  at Microsoft.CodeAnalysis.Text.SourceText+LineInfo.get_Item (System.Int32 index) [0x0000f] in <02f1a35137194cc3b7bab26f0cb540aa>:0 \n  at OmniSharp.Extensions.TextExtensions.GetPositionFromLineAndOffset (Microsoft.CodeAnalysis.Text.SourceText text, System.Int32 lineNumber, System.Int32 offset) [0x00006] in <54fef48092c04ff98616eebe03ad0555>:0 \n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetTextSpan (OmniSharp.Models.V2.CodeActions.ICodeActionRequest request, Microsoft.CodeAnalysis.Text.SourceText sourceText) [0x00028] in <47d11c951b2c467ba3d5b0bfebca06c3>:0 \n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.BaseCodeActionService`2[TRequest,TResponse].GetAvailableCodeActions (OmniSharp.Models.V2.CodeActions.ICodeActionRequest request) [0x00128] in <47d11c951b2c467ba3d5b0bfebca06c3>:0 \n  at OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService.Handle (OmniSharp.Models.V2.CodeActions.GetCodeActionsRequest request) [0x0006b] in <47d11c951b2c467ba3d5b0bfebca06c3>:0 \n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request) [0x00099] in <15a25893e84240228920acfa2b3190eb>:0 \n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <15a25893e84240228920acfa2b3190eb>:0 \n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <15a25893e84240228920acfa2b3190eb>:0 \n  at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000e7] in <871e49cde2fe4baf972bea6b4d99c013>:0 "

and sometimes both when it’s feeling generous 😜

Environment information

VSCode version: 1.52.1 C# Extension: 1.23.8

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.405 Commit: 65f9d75b1c

Runtime Environment: OS Name: Mac OS X OS Version: 10.16 OS Platform: Darwin RID: osx.10.16-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.405/

Host (useful for support): Version: 3.1.11 Commit: f5eceb8105

.NET Core SDKs installed: 1.0.0-preview2-003148 [/usr/local/share/dotnet/sdk] 2.1.4 [/usr/local/share/dotnet/sdk] 2.1.805 [/usr/local/share/dotnet/sdk] 3.0.103 [/usr/local/share/dotnet/sdk] 3.1.102 [/usr/local/share/dotnet/sdk] 3.1.200 [/usr/local/share/dotnet/sdk] 3.1.405 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.11 [/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
csharp ms-dotnettools 1.23.8

YEARS later, still experiencing this issue. just started happening randomly. shits so annoying

In the bottom status bar of vscode, there is a project/solution selector. For my workspace and solution, OmniSharp was only selecting one of the projects as “the project scope”. I noticed this by looking at the OmniSharp logs, and wondering why it loaded the server in that project folder. Once I clicked the project name in the status bar, and changed the scope to the solution, all the language server features started working in the code file I was using (that was in a different project).

So there is probably a bug to be made here – vscode/omnisharp doesn’t find the solution file which in my case is located at: [workspace folder]/src/mysolution.sln, and instead just chooses one of the projects, not even the first alphabetically.