20

When I start editing a C# file I get this warning message

Some projects have trouble loading. Please review the output for more details.

I check the output and this is what I find

Starting OmniSharp server at 2/17/2021, 6:06:51 AM
    Target: /Users/zeyad/Documents/Sandbox/CSharpTut

OmniSharp server started with Mono 6.12.0.
    Path: /Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/OmniSharp.exe
    PID: 1391

[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 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            2: StandAlone 16.8.0 - "/Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/.msbuild/Current/Bin"
[warn]: OmniSharp.CompositionHostBuilder
        It looks like you have Mono installed which contains a MSBuild lower than 16.8.0 which is the minimum supported by the configured .NET Core Sdk.
 Try updating Mono to the latest stable or preview version to enable better .NET Core Sdk support.
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 16.6.0 - "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin"
            CscToolExe = csc.exe
            CscToolPath = /Users/zeyad/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.7-beta.29/omnisharp/.msbuild/Current/Bin/Roslyn
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[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.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/zeyad/Documents/Sandbox/CSharpTut'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/Users/zeyad/Documents/Sandbox/CSharpTut'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/zeyad/Documents/Sandbox/CSharpTut'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/zeyad/Documents/Sandbox/CSharpTut' on host 1365.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj
[fail]: OmniSharp.MSBuild.ProjectLoader
        This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. 'omnisharp.useGlobalMono':'always' in C# Extension for VS Code).
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj'.
/Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj
/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1193,5): Error: This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. 'omnisharp.useGlobalMono':'always' in C# Extension for VS Code).

[fail]: OmniSharp.MSBuild.ProjectManager
        Attempted to update project that is not loaded: /Users/zeyad/Documents/Sandbox/CSharpTut/Zeyad.csproj
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 0.

I checked the solution they wrote solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. 'omnisharp.useGlobalMono':'always' in C# Extension for VS Code). And it fixed the problem, but the next day the problem occurred again!

Here is what I added in my settings.json

"omnisharp.path": "latest",
"omnisharp.useGlobalMono": "always"

The extensions I have for C# are C# extension and Roslynator.

Is there something missing to completely set up visual studio code for C#? I'm completely new to C# and I would really appreciate any help to get the same smooth feeling as in other programming languages like JavaScript or Golang

Note: I use Mac, but does this make any difference?

Zeyad Shaban
  • 896
  • 1
  • 8
  • 23
  • 1
    Sounds like you need to update Mono – Aluan Haddad Feb 17 '21 at 04:49
  • I have 6.12.0.90 which i think is the latest, but which package should I get? The Visual studio channel or Stable Channel? – Zeyad Shaban Feb 17 '21 at 12:29
  • I'm not certain because I don't have a Mac available to check at the moment but the error message above indicates a version mismatch – Aluan Haddad Feb 17 '21 at 13:54
  • After I solved this error I got another error, Visual Studio Code now highlighted every single line as an error, for example, `using System` `The type or namespace name 'System' could not be found` I tried to restart OmniSharp and do every thing I can but still whenever I fix an error I get another error, Why can't I code normally in C# like other languages? Do I need a Windows instead of a Mac? Do I need to move from vs code? – Zeyad Shaban Feb 17 '21 at 16:49
  • It should work fine on a Mac. But you need to ask a separate question because it's different problem now – Aluan Haddad Feb 17 '21 at 16:54
  • Also checkout [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/) – Aluan Haddad Feb 17 '21 at 17:00
  • I will do some more researches first before asking, thanks for the help – Zeyad Shaban Feb 17 '21 at 17:05

11 Answers11

34

Fix that by theses steps:

  1. Update Mono for Mac in: https://mono-project.com/download/
  2. VS Code > C# Enxtension (installed) > Extension setting > search for : omnisharp.useGlobalMono':'always' > set the option to Always
tmri88
  • 356
  • 4
  • 3
29

There are two ways to fix that problem.

The first one: Check the version of your C# extension. If you are in 1.25.0, you need to go to the extension settings to set omnisharp.useModernNet to false.

The second: If you are in version 1.25.0, revert your version to 1.24.0. Make sure to set omnisharp.useGlobalMono to always.

Airinfinite
  • 291
  • 3
  • 2
  • 4
    Setting `omnisharp.useModernNet` to `false` worked perfectly. I did need to restart vs-code for things to take effect. – jaxoncreed Jun 05 '22 at 04:31
  • 2
    This works for 1.25.0! For Mac users 1) Go to user folder and press Cmd + Shift + . to reveal hidden Library folder 2) Go to `Library/Application Support/Code/User/settings.json` 3) add `"omnisharp.useModernNet": false` 4) Restart VS Code and you'll see in the C# log that it installs 'OmniSharp for OSX (Mono / x64)' – Aidan Wolf Jul 05 '22 at 15:51
  • On ubuntu, settingg userModernNet to false and manually installing mono-devel https://www.mono-project.com/download/stable/ after installing dotnet-sdk from microsoft made vscode install Omnisharp correctly and everything appears to be working... – gordon_freeman Mar 31 '23 at 16:31
  • This seems to be the correct answer now for versions 1.25.x – shoopi Apr 23 '23 at 18:16
16

This worked for me:

  1. Install latest C# extension
  2. Install latest Mono for MAC: https://mono-project.com/download/
  3. Update VSCode ~/Library/Application Support/Code/User/settings.json as follow:
   {
    ...
    "omnisharp.useGlobalMono": "always",
    "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current"
   }

Don't need "omnisharp.path": "latest" because I don't want the extension check for update every time.

Ken
  • 161
  • 1
  • 3
11

Just a heads-up for those coming from a more recent timeframe. Omnisharp deprecated the useGlobalMono variable for their latest versions. Took me many hours but once I reverted my Omnisharp back to 1.24.0 (from 1.25.0) it all started working again

belopolskya
  • 111
  • 1
  • 2
3

I had the same problem on my MacBook pro running MacOS 12.4

To fix it, I had to:

  • download and install the dotnet sdk

  • download and install mono (https://mono-project.com/download/)

  • add both the paths in the termninal

  • running this: sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet where /usr/share/dotnet/dotnet should be replaced with wherever the .NET SDK installer for your platform was installed to

  • add both the paths in ~/.zshrc and source it

  • add both the paths in VSCode (settings -> search for mono and dotnet), get the path by running which mono and which dotnet. You can do this in both the user and the workspace tab. I did both. I also set the sdk path and version specifically.

  • Turn off useModernNet in VSCode

Some of these steps were probably unnecessary or redundant. But only after I tried all of these steps I finally got it to work. This link really helpt me: https://github.com/OmniSharp/omnisharp-vscode/wiki/Troubleshooting:-'The-.NET-Core-SDK-cannot-be-located.'-errors.

UPDATE: I should also add that I had to redo this for every project. An easier solution turned out to be to just install Visual Studio for Mac (the one with the purple icon) instead of Visual Studio Code. There I didn't have to add anything.

Mister_CK
  • 668
  • 3
  • 13
  • Thank you very much. I did not have to do steps 4 and 5. But steps 6 and 7 (with the first several steps) are critical. – Weiming Hu Sep 25 '22 at 19:36
  • I should also add that I had to redo this for every project. An easier solution turned out to be to just install Visual Studio for Mac (the one with the purple icon) instead of Visual Studio Code. There I didn't have to add anything. – Mister_CK Sep 27 '22 at 07:29
  • I also had to download mono and add it to my path (Note: In the C# extension I set `Mono Path` as well, but I'm not sure it was necessary) – Blundering Philosopher Jan 04 '23 at 21:41
2

Base on the comment from this here, reverting the C# extension solved the problem on a M1 mac. I reverted from C# extension version 1.25.0 to 1.24.4.

1

For the recent version of Omnisharp just uncheck the useModernNet in VS code C# extension setting as shown in the screenshot. enter image description here

Abdessamad Doughri
  • 1,324
  • 2
  • 16
  • 29
1

Still need to revert to 1.24.4 for M1 mac as for now (Nov.2022)

Heying
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 25 '22 at 11:57
  • 1
    What more should he say? It works. I followed his advice. I've spent the last 4 hours struggling with strange error messages. Now they've gone :P – Hugh Perkins Dec 29 '22 at 20:10
1

I am testing on macbook air m1 to work with Unity. Extension version 1.25.4 As the settings in VSCode say, you can't use ModernNet with Unity. Si you need to ad this to your settings.

"omnisharp.useModernNet": false,

On my machine, I installed c# extension first and then installed dotnet and mono. This seems to had messed up things. When I applied the setting above it was complaining that it can't find an OmniSharp.exe file. The last hack I had to do was deleting the extension directory and installing the extension again.

rm -rf ~/.vscode/extensions/ms-dotnettools.csharp-1.25.4-darwin-arm64

Now it works.

shampoo
  • 1,173
  • 12
  • 22
1

Update:
Mac M1 13.3.1
C# Extension for VSCode: v2.0.320

  • download and install the dotnet sdk
  • download and install mono (https://mono-project.com/download/). (Stable channel)
  • Turn off useModernNet in VSCode under Omnisharp
  • Set paths to both mono and dotnet in VSCode settings under Omnisharp
  • Mono path: /Library/Frameworks/Mono.framework/Versions/Current
  • dotnot path: /home/username/dotnet/sdks/7.0.306 (Replace username and donot version number accordingly)
iqra
  • 1,061
  • 1
  • 11
  • 18
0

For those who stuck on this issue after renaming your Unity project:

  1. Go to your unity project root folder
  2. Remove all of the folders and files except "Assets/", "Packages/", and "ProjectSettings/" folders.