Cannot get code completion to work in Visual Studio Code (OmniSharp issue?)

I’ve been trying all day to get code completion to work in Visual Studio Code, which at some point worked, but now it doesn’t. Does anyone have the same problem? Or could someone post the version numbers of their working configuration? I’m on Windows 10 x64.

Installed extensions

Installed .NET SDKS

Visual Studio Code Version

6336645--703536--upload_2020-9-22_13-18-3.png

Unity package installed

I’ve tried both versions 1.2.2 (latest) and 1.2.1

Additional

I’ve also installed .NET Framework 4.6 Targeting Pack as per the suggestion of this guide (which I followed): Visual Studio Code and Unity

Problem Description
Code completion does not work (see first image). This is caused I think by OmniSharp not understanding the project (?) and crashing.

I’m posting the OmniSharp log. Note that the crash is not related to SimpleCameraController.cs, as it happens with any script. Note that it happens in any new or existing project. I’ve also tried to ‘regenerate project files’ in the external tools section.

Any help would be greatly appreciated!

/*
Starting OmniSharp server at 9/22/2020, 1:11:31 PM
    Target: l:\repositories\newtestproject\newtestproject\newtestproject.sln

OmniSharp server started.
    Path: c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\OmniSharp.exe
    PID: 1384

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Community 2017 15.9.28307.1259 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
            2: StandAlone 16.8.0 - "c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin"
[warn]: OmniSharp.CompositionHostBuilder
        It looks like you have Visual Studio lower than VS 2019 16.3 installed.
Try updating Visual Studio to the most recent release to enable better MSBuild support.
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin"
            CscToolExe = csc.exe
            CscToolPath = c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\Roslyn
            MSBuildExtensionsPath = c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild
            MSBuildToolsPath = c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in 'l:\repositories\newtestproject\newtestproject'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in 'l:\repositories\newtestproject\newtestproject\newtestproject.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'l:\repositories\newtestproject\newtestproject\Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for 'l:\repositories\newtestproject\newtestproject\Assembly-CSharp-Editor.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in 'l:\repositories\newtestproject\newtestproject'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: l:\repositories\newtestproject\newtestproject\Assembly-CSharp.csproj
[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.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location 'l:\repositories\newtestproject\newtestproject' on host 7824.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file 'l:\repositories\newtestproject\newtestproject\Assembly-CSharp.csproj'.
l:\repositories\newtestproject\newtestproject\Assembly-CSharp.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The expression ""Assets\Scripts\SimpleCameraController.cs".GetPathsOfAllDirectoriesAbove()" cannot be evaluated. Method 'System.String.GetPathsOfAllDirectoriesAbove' not found.  c:\Users\Username\.vscode\extensions\ms-dotnettools.csharp-1.23.2\.omnisharp\1.37.1\.msbuild\Current\Bin\Roslyn\Microsoft.Managed.Core.targets
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1)
   at Microsoft.Build.Evaluation.Expander`2.Function`1.Execute(Object objectInstance, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation)
   at Microsoft.Build.Evaluation.Expander`2.ItemExpander.IntrinsicItemFunctions`1.<ExecuteStringFunction>d__13.MoveNext()
   at Microsoft.Build.Evaluation.Expander`2.ItemExpander.<Transform>d__0`1.MoveNext()
  
(...the call stack does on for a bit, then an similar crash, then...)

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: l:\repositories\newtestproject\newtestproject\Assembly-CSharp.csproj
[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: l:\repositories\newtestproject\newtestproject\Assembly-CSharp-Editor.csproj
[info]: OmniSharp.OmniSharpWorkspace
        Miscellaneous file: l:\repositories\newtestproject\newtestproject\Assets\testscript.cs added to workspace
*/

1 Like

What is your external editor set to in Unity?

I’ve both tried “Visual Studio Code” and the custom option where I pointed it the .exe. Unity detects that and sets it to “Visual Studio Code”. As mentioned, I have regenerated project files (also tried first removing them).

After 1,5 days of struggling with this, I’ve given up and did a complete reinstall of Windows 10 and all programs involved. The good news is that it works now.

Did I mention I hate computers?

For anyone encountering the same problem in the future, I’m sorry that I can’t be of any help. All I know now is that a clean OS install plus this guide works, currently. The guide is a bit untidily written regarding different unity versions, but I can confirm it works with the latest 2020 release.

3 Likes

I’ve also been experiencing the same whenever I load a script on vs code.

My current vscode version
Version: 1.49.3

My current unity version: 2020.1.3f1

I am running this on pop os 20.04 and will post updates if I find a fix.

I found the solution here on OmniSharp GitHub forum, answer posted by user rchande.
Installing .NET Framework 4.7.1 Developer Pack from .NET SDKs for Visual Studio solved my issue.

14 Likes

@Samael777 thanks installing version 4.7.1 worked for me I had 4.8 installed and this is not compatible with unity!
Installing this allowed omnishark to understand the unity output :slight_smile:

3 Likes

@Samael777 That worked for me as well :slight_smile:

@Samael777 Installing 4.71 worked for me as well! thanks so much!

Downloading the .NET Framework almost worked for me, but I was still getting a lot of the omnisharp errors listed here. The problem for me seemed to be that I had the latest versions of everything installed. When I first downloaded Unity I might not have gone through the Unity Hub, but I didn’t end up with Visual Studio installed, so I downloaded the latest version. That does not seem to work, in that it results in all of these errors. I uninstalled everything. It turns out that Unity 2020.2 wants Visual Studio 2019, and (I think) only .NET Core 3.1 SDK (not the latest version, which is .Net 5.0 at this time).
Installing Unity 2020.2 through Unity Hub seemed to include the 2019 version of Visual Studio - yay! - and then I downloaded and installed .NET Core 3.1. I had already installed the .NET Framework 4.7.1 Developer Pack listed above, so that may have helped as well.
The following page was quite helpful but didn’t list the versions of everything that are needed: Visual Studio Code and Unity

Thanks! Installing 4.7.1 and regenerate the project files solved the issue for me.

2 Likes

Thank you a lot! I struggled for several days with this, and now it seems to work fine!!!

1 Like

Thanks you so much man !

1 Like

I cannot thank you enough. This worked for me.

Same Problem. Same Solution :confused:

for anyone on linux (i am on ubuntu 20.04/mint 20.3), i got the same error, i ended up installing the .net framework 6.x

and then i installed the C# extension version 1.24.4
the 1.25.0 version (latest) was so buggy, and didn’t work.

try downloading .NET Framework 4.7.1 developer pack, it solved all my issues