10

I have a dotnet core console app I generated from the cli via

dotnet new console -n EODG.VsCodeTester.Cli

Using the C# Extensions extension, I right click on the project folder in VSCode, and click "New C# Class".

The class/file opens just fine, but Omnisharp doesn't appear to recognize the file/class. From Program.cs, the class doesn't show up in the code completion, and the codelens in the new class doesn't show up.

The following is outputted from the OmniSharp log...

[info]: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
        Could not find document for file c:\Users\elrod\src\test\src\EODG.VsCodeTester.Cli\Cat.cs

Now, if I restart OmniSharp, it recognizes the new file just fine... but it's kind of a pain to restart omnisharp everytime I make a new class/interface or rename them. I've never seen this before, and I've been doing dotnet core development in vscode since v1.

I tried googling OmniSharp "Could not find document for file"... and it said No results found for OmniSharp "Could not find document for file".... so, that's nice.

Pertinent Details

  • OS: Windows 10 (fresh install... like less than 2 hours old)
  • VSCode version: 1.50.1
  • OmniSharp version: 1.23.5
  • Dotnet version: 3.1.403

I will be more than happy to provide any other details I can.

Thanks, y'all!

RevrenLove
  • 508
  • 6
  • 14

3 Answers3

10

It looks like OmniSharp version 1.23.5 might be busted... I reverted to version 1.23.3, and things work as expected now. Possibly related to this issue on their git repo.

UPDATE: updating to v1.23.6 resolves this issue.

RevrenLove
  • 508
  • 6
  • 14
  • 1
    You saved my week! I had the same problem in Mac – Carlos Moreno Nov 13 '20 at 08:28
  • 3
    It may resolve it in some circumstances but clearly it doesn't not solve it in all cases. I am on version 1.23.6 and I still see this problem. – Manfred Nov 20 '20 at 22:04
  • @Manfred, does the problem happen when you revert the extension to 1.23.3? – RevrenLove Nov 20 '20 at 22:26
  • @JFromTheSticks It makes no difference. I even tried the most recent beta. Meanwhile I ran a few more experiments. It appears as if this is relate to the issue that WSL2 does not generate inotify events. As a result if a Windows folder is mounted into a Linux container, this will cause a number of problems including this one. I intend to write an article in the next few weeks to explain in details including how to resolve. – Manfred Nov 21 '20 at 08:17
  • 1
    Also, if someone stumbles over this question, here is another finding re omnisharp. It relies on `ps` being available in the dev container. If you use the .NET 5 SDK base image, this is not installed. You need to create a Dockerfile and in it install the missing `ps`. For an example see this Dockerfile: https://github.com/ManfredLange/issue-201121/blob/main/.devcontainer/Dockerfile – Manfred Nov 21 '20 at 08:20
  • 1
    As promised I wrote an article that describes the details of the root cause of the problem I faced (dev container with WSL2 and mounted windows folder) and how to avoid it: ["Docker Desktop on WSL2: The Problem with Mixing File Systems"](https://manfredmlange.medium.com/docker-desktop-on-wsl2-the-problem-with-mixing-file-systems-a8b5dcd79b22) – Manfred Nov 29 '20 at 21:03
  • I'm getting the same issue in 1.23.8. – Nathan Goings Dec 19 '20 at 05:41
2

What worked for me on my mac, was that in settings, search for omnisharp, then look for the option that says Omnisharp: Use Global Mono and set it to always.

-1

Steps to follow to make it work:

  1. Find Assembly-CSharp.csproj.
  2. Find the field under which your old script names are present for compilation.
  3. Add the new script name.
  4. Save in Unity. Restart VS Code if required.

It should get solved.

asmitB
  • 19
  • 5
  • The question has no mention of Assembly-CSharp.csproj, scripts, or Unity. Also, if you'll note in the accepted answer, this was merely a bug in that particular release of OmniSharp. Cheers! – RevrenLove Sep 10 '22 at 21:20