Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnisharp Update - Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable. #4489

Closed
mdmoura opened this issue Apr 9, 2021 · 36 comments · Fixed by #4492

Comments

@mdmoura
Copy link

mdmoura commented Apr 9, 2021

Issue Description

Visual Studio Code just automatically updated Omnisharp and now I get the error:
Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.

A few hours ago it was working without any problem ...

Logs

OmniSharp log

[ERROR] Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.

Environment information

VSCode version: 1.55.1
C# Extension: 1.23.10

Mono Information There is a problem with running OmniSharp on mono: Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.102 Commit: 71365b4d42

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

Host (useful for support):
Version: 5.0.2
Commit: cb5f173b96

.NET SDKs installed:
3.1.405 [/usr/local/share/dotnet/sdk]
5.0.102 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
Angular2 johnpapa 11.0.0
azure-account ms-vscode 0.9.8
azure-pipelines ms-azure-devops 1.183.0
csharp ms-dotnettools 1.23.10
docker-explorer formulahendry 0.1.7
jupyter ms-toolsai 2021.5.702919634
markdown-all-in-one yzhang 3.4.0
python ms-python 2021.3.680753044
remote-containers ms-vscode-remote 0.166.1
rest-client humao 0.24.5
typescript-hero rbbit 3.0.0
vscode-docker ms-azuretools 1.11.0
vscode-mjml mjmlio 1.0.4
vscode-todo-highlight jgclark 2.0.1
vscode-yaml redhat 0.17.0
@krrg
Copy link

krrg commented Apr 9, 2021

Same thing here; it was working fine with 1.23.9, but the 1.23.10 update is completely broken for me.

I've tried setting "omnisharp.useGlobalMono": "never", but Omnisharp is still throwing the same error, refusing to format files or offer any Intellisense.

Current workaround is to force downgrade to 1.23.9.

@filipw
Copy link
Contributor

filipw commented Apr 9, 2021

very sorry to hear you ran into these issues. there is an unfortunate bug introduced in the last release, where the extension fails to start when global Mono is not installed on the machine (also present if you configured it to not use global Mono).

there should be a hotfix as soon as possible, for now a workaround is to install a global Mono https://www.mono-project.com/download/preview/ then it will work fine (also with the setting "omnisharp.useGlobalMono": "never")

edit: the PR with the fix is here #4492

@devantler
Copy link

devantler commented Apr 9, 2021

@filipw
There also seems to be problems with the new Microsoft.AspNetCore.Razor.VSCode.BlazorWasmDebuggingExtension. I have dotnet on the path, but it throws this error when trying to attach to a hosted Blazor Webassembly app.

Launching debugging proxy from /Users/nikolaiemildamm/.vscode/extensions/ms-dotnettools.blazorwasm-companion-1.0.0/BlazorDebugProxy/BrowserDebugHost.dll
ERROR: It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '5.0.0' was not found.
  - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

Here is proof dotnet is on the path with the required framework:

image

This is my launch configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch and Debug Hosted Blazor WebAssembly App",
            "type": "blazorwasm",
            "request": "launch",
            "hosted": true,
            "preLaunchTask": "npm run build:debug",
            "program": "${workspaceFolder}/src/Presentation/WebApp/Server/bin/Debug/net5.0/EcosystemMapGenerator.Presentation.WebApp.Server.dll",
            "cwd": "${workspaceFolder}/src/Presentation/WebApp/Server"
        }
    ]
}

@JoeRobich
Copy link
Member

@mdmoura @krrg @niem94 We have a prerelease build with Filip's fix - https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.23.11. Will be validating and releasing this afternoon. Here are instructions for installing our prerelease builds if you would like to upgrade now - https://github.com/OmniSharp/omnisharp-vscode/wiki/Installing-Beta-Releases

@JoeRobich
Copy link
Member

There also seems to be problems with the new Microsoft.AspNetCore.Razor.VSCode.BlazorWasmDebuggingExtension. I have dotnet on the path, but it throws this error when trying to attach to a hosted Blazor Webassembly app.

@captainsafia which repo should we move this issue to?

@captainsafia
Copy link
Member

You can move it to the aspnetcore repo.

@krrg
Copy link

krrg commented Apr 9, 2021

Confirmed, 1.23.11 fixes the issue. 🎉
Thanks for the fast turnaround on this!

@ericdrobinson
Copy link

ericdrobinson commented May 6, 2021

I'm still seeing this with a Unity project. My environment details:

  • macOS 10.14.6
  • Unity 2019.4.23
  • VSCode 1.56.0
  • OmniSharp 1.23.11
  • Mono 6.12.0.122

The error I see when attempting to start OmniSharp is:

[ERROR] Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.

I have attempted to regenerate the solution files from within Unity. I have restarted VSCode. I confirmed that my "omnisharp.useGlobalMono" is indeed set to "always". I still have this issue.

Any ideas? Is this still a bug for certain configurations?

For the record, typing which mono in the VSCode terminal shows Mono installed here:

/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono

The project where I'm seeing this occur is new. Older projects do not appear to suffer from this issue.

@JoeRobich
Copy link
Member

@ericdrobinson Sorry you are runnign into issues. Not sure why mono wouldn't be on your path. I know that on Mac, the environment variables that an application can see are based on how the application was launched (from the dock, from the commandline, etc). You can set the omnisharp.monoPath settings to /Library/Frameworks/Mono.framework/Versions/Current so that the path is always searched.

@ericdrobinson
Copy link

@JoeRobich Thanks for the response. Some responses in-kind:

I know that on Mac, the environment variables that an application can see are based on how the application was launched (from the dock, from the commandline, etc)

Launched from the dock. OmniSharp works fine in some pre-existing projects from that launch. The project I'm experiencing this issue with was created in the same VS Code process as the working projects. VS Code's terminal (which starts with the same environment as VS Code itself, as I understand things) is able to locate mono using which mono and identifies the aforementioned path.

You can set the omnisharp.monoPath settings to /Library/Frameworks/Mono.framework/Versions/Current so that the path is always searched.

Why is this global-only (User setting versus Workspace setting)? I expect that someone may want to override the specific mono-path on a workspace-based setting if for no other reason than to test different versions or ensure that some environments are locked to a known-working version. Is there a specific reason for such a decision?

In other news, using the setting suggested above does enable the problematic project to use OmniSharp. That said, I've started seeing stuff like this in the OmniSharp Log:

[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Assembly-CSharp-Editor
[fail]: OmniSharp.MSBuild.ProjectLoadListener
        Unexpected exception got thrown from project load listener: System.NullReferenceException: Object reference not set to an instance of an object
  at OmniSharp.MSBuild.ProjectLoadListener.GetSdkVersion (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0000b] in <9ecc61c9716b45d19f58afb1114317db>:0 
  at OmniSharp.MSBuild.ProjectLoadListener.ProjectLoaded (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0001a] in <9ecc61c9716b45d19f58afb1114317db>:0 

This now happens in both previously working and previously not working projects. Error/warning reporting looks to be unaffected, however, and features like IntelliSense do work. I include it here for completion's sake. I should also point out that this output was, to my recollection, not present in the OmniSharp log for previously working projects before changing the global mono path. No idea what's going on or if this actually even matters.

@JoeRobich
Copy link
Member

@ericdrobinson Glad things are working a little better.

VS Code's terminal (which starts with the same environment as VS Code itself, as I understand things) is able to locate mono using which mono and identifies the aforementioned path.

I believe the terminal simply hosts a shell which would construct its environment with additions from its config files.

Why is this global-only (User setting versus Workspace setting)?

Many users and projects commit workspace settings to their repo. This setting, if committed, could cause issue for other team members who use Mono and might be different platforms. That being said. We have certainly recieved feedback that our users would like more flexibility with these settings.

Unexpected exception got thrown from project load listener: System.NullReferenceException: Object reference not set to an instance of an object
at OmniSharp.MSBuild.ProjectLoadListener.GetSdkVersion

This seems to indicate that the PATH didn't include the dotnet installation folder either.

@ericdrobinson
Copy link

@JoeRobich Thanks again for the responses:

I believe the terminal simply hosts a shell which would construct its environment with additions from its config files.

So why, then, would previous versions of OmniSharp work without issue but suddenly break for one new project?

Many users and projects commit workspace settings to their repo. This setting, if committed, could cause issue for other team members who use Mono and might be different platforms. That being said. We have certainly recieved feedback that our users would like more flexibility with these settings.

I guess I don't understand why these settings can't simply be available in both User and Workspace contexts? Presumably a User setting would be "global" and a "Workspace" would be local to the specific workspace (and override any global setting). This is how VSCode's own settings tend to be, right? Is there a specific reason to not provide this flexibility?

This seems to indicate that the PATH didn't include the dotnet installation folder either.

Interesting. Any advice on how to address this?

@JoeRobich
Copy link
Member

OmniSharp works fine in some pre-existing projects from that launch. The project I'm experiencing this issue with was created in the same VS Code process as the working projects.

How was the project that display's the issue opened in VS Code? VS Code's File > New Window? code . from the VS Code Terminal?

Is there a specific reason to not provide this flexibility?

Nothing other than the intial reasoning that made it a user setting.

Interesting. Any advice on how to address this?

It likely has the same root problem that is causing Mono not to be avilable from the PATH.

@soloschenko-grigoriy
Copy link

soloschenko-grigoriy commented May 8, 2021

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

@ericdrobinson
Copy link

@JoeRobich Some responses:

How was the project that display's the issue opened in VS Code? VS Code's File > New Window? code . from the VS Code Terminal?

Select "Open C# Project" from the "Assets" menu in Unity. To be fair, I did not actually try opening the project by creating a New Window and then use "Open Recent" to see if that changed anything. My assumption going into this was that the PATH was configured at application launch and all windows would share that setup, regardless of how new projects were opened. Is that not the case?

It likely has the same root problem that is causing Mono not to be avilable from the PATH.

Sure. Is that something that can be configured in settings somewhere? Also, what exactly is not working when that failure occurs?

@qcha0s
Copy link

qcha0s commented May 17, 2021

1.56.x is just broken for Unity. multiple things don't load, git not seeing the repo and telling me there is no repo and to initialize one, OmniSharp can't find mono - Nothing above was helpful, Reverted to 1.55.2 (https://code.visualstudio.com/updates/v1_55) - No issues, everything works as expected.

@ericdrobinson
Copy link

@qcha0s Is this something that should be reported to the VSCode issues, then? Or did you attempt to do anything about getting a specific earlier version of OmniSharp before changing your VSCode version?

I imagine that the git issues you described had very little if anything to do with the OmniSharp extension...

@j1mmie
Copy link

j1mmie commented Jun 2, 2021

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

Worked for me 🙌

@ghostlhq
Copy link

ghostlhq commented Jun 8, 2021

Just in case anyone else gets here looking for a solution
Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

Worked for me 🙌

Me either, thx~ Totally save my day : )

@jonmumm
Copy link

jonmumm commented Jun 10, 2021

+1 worked for me

@yrcloud
Copy link

yrcloud commented Jul 4, 2021

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

+1 worked for me too

@chestermjr
Copy link

+1, thank you!

@ardunster
Copy link

ardunster commented Jul 26, 2021

Regenerating my project files did nothing. Terminal can find mono:

% which mono
/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono

I tried setting "omnisharp.monoPath" to "/Library/Frameworks/Mono.framework/Versions/Current", "/Library/Frameworks/Mono.framework/Versions/Current/", "/Library/Frameworks/Mono.framework/Versions/Current/Commands/", none of which make any difference, every time I open the project (via clicking a script inside Unity, or via simply reloading the program with the last workspace) I get [ERROR] Error: Unable to find Mono. Update the "omnisharp.monoPath" setting to point to the folder containing Mono's '/bin' folder.

I do also have "omnisharp.useGlobalMono": "always" set.

This is with version 1.23.13 of the C# extension.

I have no intellisense or anything useful from the C# extension except maybe a few snippets (and some really annoying behavior on spacebar that I had to disable using autosuggest on commit character over).

Edit: following directions from the vscode unity doc I downloaded and installed the latest version of mono and then restarted my laptop. It seems to be working now.

I did not install the Visual Studio Code editor package for Unity. it hasn't been updated in about 2 years and the features the page says are missing (generating csproj and sln files, and opening scripts from unity) are present and working in the 2020 lts version of Unity that I have this project in.

@MahdiFarzami
Copy link

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

this solution worked for me

@ghost
Copy link

ghost commented Oct 4, 2021

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

After Adding "omnisharp.useGlobalMono" to "Always" and then following the steps above got it working in no time. It was hitting regenerate project files for me. Using VS code and unity on Mac! Thanks for this thread everyone!

@sawirricardo
Copy link

Mine's not working. What did you guys do other than:

  • setting omnisharp.useGlobalMono to "Always"
  • Regenerate project
  • Restart, Kill Unity

I've done these, yet bear no result.

VSCode 1.60.2
Unity 2020.3.20f1
Mono 6.12.0.122
.NET SDK (5.0.401)

@anchpop
Copy link

anchpop commented Oct 13, 2021

@sawirricardo I had the same issue on my macbook, but rebooting made it work for me. Did you get it working?

@sawirricardo
Copy link

@sawirricardo I had the same issue on my macbook, but rebooting made it work for me. Did you get it working?

Rebooting works. Until I have to shut down my vscode. And secondtime I open again, the problem reappears again. I made it work again by restarting Unity, though.

@carmenmckie
Copy link

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

thank you!

@anchpop
Copy link

anchpop commented Nov 11, 2021

@JoeRobich Just so you know this fix is incomplete. It works after a reboot or after force quitting vscode, but doesn't work after closing and reopening vscode normally (on my mac)

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.402
 Commit:    e9d3381880

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

Host (useful for support):
  Version: 5.0.11
  Commit:  f431858f8b

.NET SDKs installed:
  2.1.818 [/usr/local/share/dotnet/sdk]
  5.0.402 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

@ther0ok1eboy
Copy link

I have resolved this problem due to installing Mono and mono-msbuild and my computer is Arch.

@gregharding
Copy link

The original issue might have been fixed but I am seeing the same error while trying to open both C# projects from two different Unity instances. One project will open fine but Intellisense will not start in the second project and the OmniSharp log shows the same 'Unable to find Mono' error.

I am currently running macOS 11.6, VSCode 1.64.2, OmniSharp 1.24.0, Mono 6.12.0.162 (but it's been happening for a looong time).

Using @JoeRobich's suggestion above, I edited the settings.json to include a manual path "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current". Now two different Unity instances can open their C# projects at the same time and both projects' Intellisense works fine.

@Astrofol
Copy link

Just in case anyone else gets here looking for a solution

Got the same issue right now, perhaps occurred after recent MacOS update. Killed vscode, killed Unity. Restarted Unity, regenerated project files (Unity -> Preferences -> External Tools) then opened vscode from within Unity (dbclick on any script). Took about a minute for intellisense to kick off but it did eventually. Hope it helps

It worked the first time then the problem returned!!

@antobom
Copy link

antobom commented Apr 25, 2022

Regenerating my project files did nothing. Terminal can find mono:

% which mono
/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono

I tried setting "omnisharp.monoPath" to "/Library/Frameworks/Mono.framework/Versions/Current", "/Library/Frameworks/Mono.framework/Versions/Current/", "/Library/Frameworks/Mono.framework/Versions/Current/Commands/", none of which make any difference, every time I open the project (via clicking a script inside Unity, or via simply reloading the program with the last workspace) I get [ERROR] Error: Unable to find Mono. Update the "omnisharp.monoPath" setting to point to the folder containing Mono's '/bin' folder.

I do also have "omnisharp.useGlobalMono": "always" set.

This is with version 1.23.13 of the C# extension.

I have no intellisense or anything useful from the C# extension except maybe a few snippets (and some really annoying behavior on spacebar that I had to disable using autosuggest on commit character over).

Edit: following directions from the vscode unity doc I downloaded and installed the latest version of mono and then restarted my laptop. It seems to be working now.

I did not install the Visual Studio Code editor package for Unity. it hasn't been updated in about 2 years and the features the page says are missing (generating csproj and sln files, and opening scripts from unity) are present and working in the 2020 lts version of Unity that I have this project in.

edit worked for me !

@chengengliu
Copy link

chengengliu commented Oct 29, 2022

The original issue might have been fixed but I am seeing the same error while trying to open both C# projects from two different Unity instances. One project will open fine but Intellisense will not start in the second project and the OmniSharp log shows the same 'Unable to find Mono' error.

I am currently running macOS 11.6, VSCode 1.64.2, OmniSharp 1.24.0, Mono 6.12.0.162 (but it's been happening for a looong time).

Using @JoeRobich's suggestion above, I edited the settings.json to include a manual path "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current". Now two different Unity instances can open their C# projects at the same time and both projects' Intellisense works fine.

Hi @gregharding I'm having exactly the same issue as you did. It works perfectly when only one project is opend but not for two projects opend together. Did you simply add the one line to the setting.json file? I have tried but still got [ERROR] Error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Fixed it. I think I am updating the wrong setting.json file. I am modifying the workspace/setting.json file. It turns out I should modify the user settings.json file.

@LightGameStudio42
Copy link

[ERROR] Error: spawn mono ENOENT

edited the settings.json to include a manual path "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/Current". Now two different Unity instances can open their C# projects at the same time and both projects' Intellisense works fine.

Drops an error for me
[ERROR] Error: spawn mono ENOENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.