Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense (omnisharp) crashes after typing. #5017

Closed
dreammixgames opened this issue Jan 21, 2022 · 21 comments · Fixed by OmniSharp/omnisharp-roslyn#2333
Closed

Intellisense (omnisharp) crashes after typing. #5017

dreammixgames opened this issue Jan 21, 2022 · 21 comments · Fixed by OmniSharp/omnisharp-roslyn#2333

Comments

@dreammixgames
Copy link

dreammixgames commented Jan 21, 2022

I posted this in the Visual Studio Code issues and they told me to post it here saying that it's the C# extension's issue. I basically try to use Intellisense and it crashes. I can use it for 1 second and then it crashes every time, giving me this error: "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object." This error happens in every project & every script. I have already done an uninstall and reinstall. I have also tried different versions of Visual Studio Code. I have also tried 3 different versions of the C# extension.

I have also used the most recent version, and neither work (currently reverted to 1.23 to see if that fixed it, but nope).

This is my entire error log:

Starting OmniSharp server at 1/21/2022, 4:57:14 PM
Target: c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Legend Maker.sln

OmniSharp server started.
Path: c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44\OmniSharp.exe
PID: 9444

Starting OmniSharp on Windows 6.2.9200.0 (x64)
info: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
info: OmniSharp.Services.DotNetCliService
Using the 'dotnet' on the PATH.
info: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 1 MSBuild instance(s)
1: StandAlone 17.0.0 - "c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild\Current\Bin"
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
MSBUILD_EXE_PATH environment variable set to 'c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild\Current\Bin\MSBuild.exe'
info: OmniSharp.MSBuild.Discovery.MSBuildLocator
Registered MSBuild instance: StandAlone 17.0.0 - "c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild\Current\Bin"
CscToolExe = csc.exe
CscToolPath = c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild\Current\Bin\Roslyn
MSBuildExtensionsPath = c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild
MSBuildToolsPath = c:\Users\nicep.vscode\extensions\ms-dotnettools.csharp-1.23.17.omnisharp\1.38.1-beta.44.msbuild\Current\Bin
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
info: OmniSharp.WorkspaceInitializer
Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
info: OmniSharp.Cake.CakeProjectSystem
Detecting Cake files in 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker'.
info: OmniSharp.Cake.CakeProjectSystem
Did not find any Cake files
info: OmniSharp.MSBuild.ProjectSystem
Detecting projects in 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Legend Maker.sln'.
info: OmniSharp.MSBuild.ProjectManager
Queue project update for 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Assembly-CSharp.csproj'
info: OmniSharp.Script.ScriptProjectSystem
Detecting CSX files in 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker'.
info: OmniSharp.Script.ScriptProjectSystem
Did not find any CSX files
info: OmniSharp.WorkspaceInitializer
Configuration finished.
info: OmniSharp.Stdio.Host
Omnisharp server running using Stdio at location 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker' on host 15756.
info: OmniSharp.MSBuild.ProjectManager
Loading project: c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Assembly-CSharp.csproj
info: OmniSharp.MSBuild.ProjectManager
Successfully loaded project file 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Assembly-CSharp.csproj'.
info: OmniSharp.MSBuild.ProjectManager
Adding project 'c:\Users\nicep\Documents\Game Projects\Legend-Maker\Legend Maker\Assembly-CSharp.csproj'
info: OmniSharp.MSBuild.ProjectManager
Update project: Assembly-CSharp
Received response for /quickinfo but could not find request.
Received response for /v2/getcodeactions but could not find request.
Received response for /v2/blockstructure but could not find request.
Received response for /v2/getcodeactions but could not find request.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at OmniSharp.Helpers.DiagnosticExtensions.<>c.b__2_0(DocumentDiagnostics x) in D:\a\1\s\src\OmniSharp.Roslyn.CSharp\Helpers\DiagnosticExtensions.cs:line 38
at System.Linq.Enumerable.d__233.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Linq.Lookup2.Create[TSource](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.GroupedEnumerable3.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
at OmniSharp.Protocol.Packet.ToString() in D:\a\1\s\src\OmniSharp.Host\Protocol\Packet.cs:line 22
at System.IO.TextWriter.WriteLine(Object value)
at System.IO.TextWriter.SyncTextWriter.WriteLine(Object value)
at OmniSharp.Services.SharedTextWriter.ProcessWriteQueue() in D:\a\1\s\src\OmniSharp.Host\Services\SharedTextWriter.cs:line 48
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

@GAGOSIAN84
Copy link

Same here. Yesterday was fine, but it omnisharp crashes today. Jan/22

@dreammixgames
Copy link
Author

Same here. Yesterday was fine, but it omnisharp crashes today. Jan/22

I'm glad to know it's not just me, because I was thinking it was just an issue with my PC at this point. I hope we can figure this out.

@terroj
Copy link

terroj commented Jan 22, 2022

The same problem, but it happened to me during saving any .cs file.

@Doire
Copy link

Doire commented Jan 22, 2022

According to the c# extension in known issues for 1.24.0 in the changelog it says:

"For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set "omnisharp.useGlobalMono": "always". The current value of "auto" will remain "never" until Mono upgrades their bundled MSBuild version."

You could try that. Seemed to work for me.

Edit
Feck, nevermind, problem returned.

@dreammixgames
Copy link
Author

dreammixgames commented Jan 22, 2022

Thanks for the info. Sucks that it's still not working :/ I'm moving over to Visual Studio 2022 for the moment,

@otaviowillow
Copy link

otaviowillow commented Jan 22, 2022

According to the c# extension in known issues for 1.24.0 in the changelog it says:

"For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set "omnisharp.useGlobalMono": "always". The current value of "auto" will remain "never" until Mono upgrades their bundled MSBuild version."

Yeah, this doesn't work nor any omnisharp settings I've tried so far

@MarkDus
Copy link

MarkDus commented Jan 22, 2022

This Is happening to me too, since yesterday. i have .Net Installed and everything!

@JoeRobich
Copy link
Member

@dreammixgames I see you have omnisharp.path set to latest in your configuration. If you remove that and restart, do you see the same issue?

@synystro
Copy link

@JoeRobich your suggestion fixed this issue here. I've set "omnisharp.path" to "" and everything works fine now. Thank you!

@rtybanana
Copy link

@JoeRobich @synystro this suggestion didn't work for me, still periodically crashes and then won't work until I restart vscode

@dreammixgames
Copy link
Author

@dreammixgames I see you have omnisharp.path set to latest in your configuration. If you remove that and restart, do you see the same issue?

Thank you! So far this has completely fixed my issue! If anyone is wondering how to do this. Go here:
image

Set this to "" instead of whatever it is set to, and save.
image

@dustinlacewell
Copy link

Hello. I'm running NixOS and using the omnisharp that ships with the extension is not possible. I must use the omnisharp-rosyln package from NixOS and therefore use omnisharp.path.

Can anyone please help me understand why clearing omnisharp.path is resolving this issue for some people? What is the actual mechanism behind why this workaround works?

@JoeRobich
Copy link
Member

@dustinlacewell Specifically it is not having omnisharp.path set to latest. When set to latest it pulls the rolling builds of O#. A bug must have been introduced in a recently merged PR.

@DaRosenberg
Copy link

DaRosenberg commented Jan 24, 2022

This looks like it could be related to a recent PR to enable running Roslyn analyzers on multiple threads.

To help narrow this down, can you try with the enableRoslynAnalyzers setting disabled and see if the problem persists?

"omnisharp.enableRoslynAnalyzers": false

Or conversely, if you don't have analyzers enabled, try with the above setting set to true instead (which switches to another implementation of the diagnostics worker) and see if that helps.

@DaRosenberg
Copy link

I repro this on latest. It seems to be a regression in the version of CSharpDiagnosticWorker.cs that does not use Roslyn. @TomasEkeli the changes to that implementation were made by you before I got involved and I never really looked at them - could you help take a look?

An alternative workaround, besides opting out of preview builds, is to turn on Roslyn Analyzer support in omnisharp.json:

{
    "RoslynExtensionsOptions": {
        "enableAnalyzersSupport": true
    }
}

This activates an implementation that does not seem to have this issue.

@DaRosenberg
Copy link

An additional finding:

If I switch to using .NET 6 instead of Mono, the issue doesn't reproduce for me.

I.e. in VS Code settings:

"omnisharp.useModernNet": true,

So issue seems specific to either the Mono build or the Mono runtime somehow.

@DavidZidar
Copy link

I tried digging in the code, but it's really hard to know what's going on without being able to debug.

But according to the stack trace, this line is what is blowing up:
https://github.com/OmniSharp/omnisharp-roslyn/blob/b4042a7389a5492ce5a892576a8df91d31488367/src/OmniSharp.Roslyn.CSharp/Helpers/DiagnosticExtensions.cs#L38

The only thing on that line that can be null is x which is the DocumentDiagnostics class created here:
https://github.com/OmniSharp/omnisharp-roslyn/blob/b4042a7389a5492ce5a892576a8df91d31488367/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs#L167

I have no idea how that could possibly be null though, here is the relevant code that calls the diagnostic worker and passes on the diagnostics to the method that throws:
https://github.com/OmniSharp/omnisharp-roslyn/blob/b4042a7389a5492ce5a892576a8df91d31488367/src/OmniSharp.Roslyn.CSharp/Services/Diagnostics/CodeCheckService.cs#L33-L55

@DavidZidar
Copy link

It could be a thread safety issue, results is just a plain List<T>:
https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs#L144

And it's modified concurrently without a lock here:
https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorker.cs#L167

Could that possibly result in items in the list that are null?

@DavidZidar
Copy link

I managed to reproduce the issue and implemented a fix, works on my machine.
OmniSharp/omnisharp-roslyn/pull/2333

@DaRosenberg
Copy link

@DavidZidar It sounds entirely plausible that you might end up with null elements in a List<T> if you're trying to do concurrent adds to the list. It also seems plausible that this kind of behavior is something that might potentially differ between Mono and .NET 6, which would explain why switching to the latter seems to work around this issue (but may of course result in missing elements or other incorrect state rather than null elements).

@DavidZidar
Copy link

@DaRosenberg I can only concur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.