Visual Studio Code Intellisense stopped to work on C# files
Asked Answered
C

4

14

I realized that I can't use ctrl + . shortcut to import other C# classes. This shortcut works just fine for other file types like typescript.

I have uninstalled and installed back again. I also installed old version of VS code too. But nothing worked.

enter image description here As I shown above, there is no import feature shows up when I do ctrl + .. Those are only the choices I was given. It's fine using without it but it's also annoying to import those files manually typed.

Coheir answered 30/1, 2018 at 17:38 Comment(0)
H
28

The C# language features in VS Code are provided by a service called OmniSharp .

A couple of things you could try:

A) Restart OmniSharp

  1. Open the Command Palette (Ctrl + Shift + P)
  2. Type Omnisharp: Restart OmniSharp

    Command Palette > OmniSharp

B) View OmniSharp Logs

  1. Open Output Panel (Ctrl + ')
  2. Select OmniSharp Log from the dropdown)

    Output Panel > OmniSharp

C) Enable OmniSharp Logging

  1. Enabling C# debugger logging in Omnisharp

    "configurations": [
        {
            "...": "...",
            "logging": {
                "engineLogging": true
            }
        },
        { "...": "..." }
    ]
    
Hill answered 30/1, 2018 at 18:16 Comment(2)
Update: Here is [fail] message: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService Error registering code fixes for Microsoft.CodeAnalysis.CSharp.AddImport.CSharpAddImportCodeFixProviderCoheir
Got it working. The issue was my dotnet framework. I repaired my dotnet framework it started to work. OmniSharp error log led me there.Coheir
T
2

I faced into a similar situation. In My case I had several .csproj files and one solution file. Make sure to add all .csproj file to .sln file.

dotnet sln add <.csproj file path>.

Make sure to restart omnisharp. In Mac -> (command + shift + p => select Omnisharp: Restart OmniSharp)

Tallbot answered 20/5, 2019 at 15:42 Comment(1)
That's the one for VSCode on a Mac!Sequestration
L
1

Something that solved it in my case was, in Unity, to set the Edit -> Project Settings -> Player -> Other Settings -> Api Compatibility Level to .NET 4.x.

Probably not appropriate in some cases, and indiciative of another issue in my Omnisharp/ VS Code setup, but just in case it helps someone.

Lacrosse answered 25/2, 2020 at 14:43 Comment(0)
O
0

Have you tried clearing out Visual Studio cache by any chance? Make sure Visual Studio is closed before attempting this. It is typically located at: C:\Users\Your User Name\AppData\Local\Microsoft\VisualStudio\

This cache could easily get corrupted and usually doesn't get cleared between re-installations.

Also, if previous doesn't work, try clearing temp directory as well - C:\Users\Your user name\AppData\Local\Temp

Few more additions to check

  • Check if Keyboard layout settings in Tools-> Options -> Environment -> Keyboard is set to Visual C# 2005

  • Check for IntelliSense settings in Tools -> Options -> Text Editor -> C# -> Formatting, for anything that may have caused the defaults to change

Hope this helps!

Osburn answered 30/1, 2018 at 18:4 Comment(3)
I don't see any files to clear. I have 14.0, 15.0, 15.0_.., Packages, SettingsLogs, vshub. Seems like these are Visual Studio folders not Visual Studio Code.Coheir
Great that you figured out the issue!!! Just a FYI - these folders contain any setting related to the Visual Studio version you are using. It is very unlikely that there's no files at all here because the moment you open VS the first time, it would create a bunch of files here (that includes user preferences and setting). Good luck!Osburn
The question relates to visual studio code - completely different from visual studio hence the missing filesHill

© 2022 - 2024 — McMap. All rights reserved.