vscode-csharp: Incorrectly reporting errors in unity project

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.4)

Product Information: Version: 1.0.4 Commit SHA-1 hash: af1e6684fd

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

VS Code version:

1.27.2

C# Extension version:

1.16.1

Steps to reproduce

I don’t have a simple repro. In my project, if I open the “Shooter.cs” file then it’s fine. If I open the “Rifle.cs” file it’s still fine. If I then click back on the open Shooter.cs file I get about 400 spurious errors.

Expected behavior

Only real errors should be reported.

Actual behavior

Almost every line of the file is reported as an error. This is the error on the rifle class itself:

The type 'Rifle' in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assets/Scripts/Rifle.cs' conflicts with the imported type 'Rifle' in 'Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assets/Scripts/Rifle.cs'. [Assembly-CSharp]
The type 'Rifle' in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assets/Scripts/Rifle.cs' conflicts with the imported type 'Rifle' in 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assets/Scripts/Rifle.cs'. [Assembly-CSharp-Editor]

This is from a reference to the rifle in the Shooter class:

The type or namespace name 'Rifle' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp, Assembly-CSharp-firstpass, Assembly-CSharp-Editor]

(This is most of the errors)

This is a reference in Shooter to an external enum:

Cannot implicitly convert type 'Shooter.LaserType [Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]' to 'Shooter.LaserType [Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]'. An explicit conversion exists (are you missing a cast?) [Assembly-CSharp-Editor]

This is the output from omnisharp when loading up:

Starting OmniSharp server at 9/17/2018, 4:57:48 PM
    Target: /Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/swatson_OSX_SVT2.sln

OmniSharp server started with Mono 5.14.0.
    Path: /Users/simonwatson/.vscode/extensions/ms-vscode.csharp-1.16.1/.omnisharp/1.32.5/omnisharp/OmniSharp.exe
    PID: 12532

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.13.6 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/usr/local/Cellar/mono/5.14.0.177/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/Users/simonwatson/.vscode/extensions/ms-vscode.csharp-1.16.1/.omnisharp/1.32.5/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 15.0 - "/usr/local/Cellar/mono/5.14.0.177/lib/mono/msbuild/15.0/bin"
            CscToolPath = /Users/simonwatson/.vscode/extensions/ms-vscode.csharp-1.16.1/.omnisharp/1.32.5/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/swatson_OSX_SVT2.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-firstpass.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-Editor.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2'.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-firstpass.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2' on host 12486.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-firstpass.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-firstpass.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-Editor.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-Editor.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Assembly-CSharp-Editor.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp
[warn]: OmniSharp.MSBuild.ProjectManager
        Unable to resolve assembly '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Temp/bin/Debug/Assembly-CSharp-firstpass.dll'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp-firstpass
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp-Editor
[warn]: OmniSharp.MSBuild.ProjectManager
        Unable to resolve assembly '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Temp/bin/Debug/Assembly-CSharp-firstpass.dll'
[warn]: OmniSharp.MSBuild.ProjectManager
        Unable to resolve assembly '/Users/simonwatson/Documents/Projects/swatson_OSX_SVT2/Temp/bin/Debug/Assembly-CSharp.dll'

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 9
  • Comments: 25 (1 by maintainers)

Most upvoted comments

Quick Update: Unity 2019.2 officially added support for VS Code via package manager. To ensure projects are generated correctly, remove all csproj files that are related to the unity project and reopen the the project from Unity in order to properly generated the proj files. You might also want to remove any old .vscode directory just to be sure that a clean vs-code compatible is generated from unity.

Will come with updates after I test this for a few days

@Aciho I think I might know what is the problem here. Do you have symbolic links in your project? Can you try setting omnisharp.path: “1.32.2” in your settings and then Ctrl+Shift+P --> Restart OmniSharp and see if the error still reproduces ?

Any updates about this issue? I still getting it on 1.17.1

Do you mean this problem? “Error occured in loading omnisharp from omnisharp.path Could not start the server due to Error: 404” Today i got it in my Unity project. Settings omnisharp.path in VS Code was “latest”.

Next way work for me:

  1. Download omnisharp from this https://github.com/OmniSharp/omnisharp-vscode/releases/download/v1.18.0-beta2/csharp-1.18.0-beta2.vsix
  2. Turn off auto-update in VS Code using: press ctrl+shift+p and choose “Extensions: Disable Auto Updating Extensions”
  3. Install downloaded csharp-1.18.0-beta2.vsix: press ctrl+shift+p in VS Code and choose “Extensions: Install from VSIX”.
  4. Change in VS Code User Settings to “omnisharp.path”: “1.32.8”
  5. Restart VS Code.

Any updates about this issue? I still getting it on 1.17.1

I’ve been seeing those same errors; I think this may actually be a Unity issue. All those paths that are being referred to are from the various .csproj files. They’re all pointing to dlls that are expected to be in the Temp/bin/Debug folder, but Unity doesn’t appear to be placing any dlls in there. At least 2017 and 2018 don’t - on my machine all those dlls end up in Library/ScriptAssemblies. Unity is generating these .csproj files automatically, so it’s possible they’re sticking the wrong paths in there by mistake.

What’s odd is that the Intellisense eventually starts working anyway for me, just takes longer than it used to to start up, and shows the little red error flame icon forever.

I have the same issue but it apperas only after I upload my repo to unity repository. It’s really annoying, always need to reopen vscode.

I was running into this on Mac, with Unity 5.6.5 yesterday… indeed, was trying to do some refactoring etc in readiness to upgrade Unity version but just adding some pretty basic class seemed to be coming up with it.

Sorry to not provide more detail, but pretty sure Photon & Coroutines were in no way implicated in my case.

@RDeluxe @BiosElement We created a beta that might help with this. Can you install it and let me know? https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.18.0-beta5

@rchande I can certainly put together a demo project, but as @RDeluxe mentioned, it resolves itself when Omnisharp is restarted. Anything I create wouldn’t show the issue until changes were made with imports or new classes and it makes no sense. Happy to put together a video and a sample project over the week though if that’d help, I’m just not sure it’d be very helpful to display the bug.

And yes, I agree the error message indicates a conflict, but even using custom namespaces and totally random function or class names cause the same problem and it doesn’t seem tied to any specific packages, but it ‘might’ be tied to Unity and how it generates the project files for vscode.

I’ve got similar intellisense errors in my dotnet core 2.1 / C# based project within vscode / omnisharp (windows 10 host, vscode 1.27.2, C# plugin 1.16.1, with git). My current repro: after opening a git diff view, hover my mouse on different symbols on the changed lines a few times, intellisense seems messed up by either not showing the correct information of the symbols or hovering on symbols away from the changed lines, the intellisense seems reporting something totally unrelated. Then after closing the diff view, a bunch of C# errors now are reported in the “Problems” tab, something along the line of “class does not contain a definition of something”, seems the intellisense database is totally messed up.

Reopen vscode would solve the intellisense problems temporarily, until the repro steps are tried again.