vscode-csharp: Error when creating new files

Issue Description

Hello!

I’m having some trouble using VSCode and the C# extension. Everytime I create a new file, the Intellisense doens’t work, not showing any errors (red underline) on the file. The OmniSharp Log output shows the following message:

    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/Mock.cs

I reinstalled VSCode and deleted all my extensions folder rm -rf ~/.vscode*, just installed the C# extension and the error persists.

I’m using VSCode version 1.50.1 on a macOS Cataline 10.15.7, dotnet sdk 3.1.403

Steps to Reproduce

Clean Install of VSCode Install C# extension Create a dotnet webapi project dotnet new webapi -n Test Create a new file Write something ex: aaaaaa

Expected Behavior

The expect behavior would be the line written with a red underscore, indicating an error.

Actual Behavior

Nothing happens, and you can check errors popping on the OmniSharp Log

[info]: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService
        Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Teste/Controllers/teste.cs

Logs

OmniSharp log

Here's the full OmniSharp Log, the error lines at the end start appearing as I create a new file and start to type on it.

Starting OmniSharp server at 11/5/2020, 4:28:59 AM Target: /Users/rafaelmaia/source/personal/dotnet/Commander

OmniSharp server started. Path: /Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/run PID: 94751

    Starting OmniSharp on MacOS 10.15.7 (x64)
    DotNetPath set to dotnet
    Located 1 MSBuild instance(s)
        1: StandAlone 16.8.0 - "/Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin"
    MSBUILD_EXE_PATH environment variable set to '/Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
    Registered MSBuild instance: StandAlone 16.8.0 - "/Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin"
        CscToolExe = csc.exe
        MSBuildToolsPath = /Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin
        CscToolPath = /Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild/Current/Bin/Roslyn
        BypassFrameworkInstallChecks = true
        MSBuildExtensionsPath = /Users/rafaelmaia/.vscode/extensions/ms-dotnettools.csharp-1.23.5/.omnisharp/1.37.3/omnisharp/.msbuild
    Detecting Cake files in '/Users/rafaelmaia/source/personal/dotnet/Commander'.
    Could not find any Cake files
    No solution files found in '/Users/rafaelmaia/source/personal/dotnet/Commander'
    Queue project update for '/Users/rafaelmaia/source/personal/dotnet/Commander/Commander.csproj'
    Detecting CSX files in '/Users/rafaelmaia/source/personal/dotnet/Commander'.
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Loading project: /Users/rafaelmaia/source/personal/dotnet/Commander/Commander.csproj
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
    Configuration finished.
    Omnisharp server running using Stdio at location '/Users/rafaelmaia/source/personal/dotnet/Commander' on host 94627.
    Successfully loaded project file '/Users/rafaelmaia/source/personal/dotnet/Commander/Commander.csproj'.
    Adding project '/Users/rafaelmaia/source/personal/dotnet/Commander/Commander.csproj'
    Update project: Commander
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs
    Could not find document for file /Users/rafaelmaia/source/personal/dotnet/Commander/Data/teste1.cs

C# log

Nothing on C# Log.

Environment information

VSCode version: 1.50.1 C# Extension: 1.23.5

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.403 Commit: 9e895200cd

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

Host (useful for support): Version: 3.1.9 Commit: 774fc3d6a9

.NET Core SDKs installed: 2.0.3 [/usr/local/share/dotnet/sdk] 2.1.3 [/usr/local/share/dotnet/sdk] 3.1.403 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [/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.5

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 10
  • Comments: 31 (12 by maintainers)

Most upvoted comments

For those of you who are still seeing this and aren’t adding non csharp files (like tcroc is) please file a new issue with specific repro steps. I use the extension every day and have yet to reproduce the issue with csharp files, so more info is needed.

1. make a new folder, cd into it

2. `dotnet new console`

3. go edit Program class, add property : `public Model MyProperty { get; set; }`

4. use `Show Fixes (ctrl+;)` to create Model `Generate type 'Model' -> Generate class 'Model' in a new file`

now Model.cs is created but Program doesn’t see the class, and you can’t see the ‘x references’ hints in the new file.

This minimal example works for me having set omnisharp.path to latest, however within a Unity project adding a new C# script isn’t recognised and I get the “Could not find document for file” warning, no autocompletions or reference counter

I’m using VSCodium 1.52.0, C# extension 1.23.7. I’m not massively familiar with C# development so please let me know what other debug info you need if you do

I did notice having this issue once when using the “latest” release. It was right after I created a new .asmdef file. I will see if I can recreate it later today.

That’s what I am doing - sorry if I wasn’t clear. I set omnisharp.path to latest and the extension still isn’t picking up new scripts in a Unity project I’m working on

The minimal example works though

@333fred Awesome thanks! I just created a new test script from Unity and it appears to be working 😃