dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

Omnisharp not working on Mac OS M1 and VS Code #5262

Open jcoble opened 2 years ago

jcoble commented 2 years ago

Hi,

I've tried so many suggestions on getting my mac os m1 to work with omni sharp with vs code. Here is the non error log that I get, just that it won't start. Nothing to go on.

Starting OmniSharp server at 6/10/2022, 7:54:04 PM Target: /Users/jcmac/mainrepos/trackmyhealthmicro/api/trackmyhealthmicro.sln

OmniSharp server started with .NET 6.0.300 . Path: /Users/jcmac/.vscode-insiders/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.1-beta.2-net6.0/OmniSharp.dll PID: 63228

[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

Here are the relevant dotnet info

jcmac@Jesses-MacBook-Pro % dotnet --list-runtimes Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] jcmac@Jesses-MacBook-Pro % dotnet --list-sdks 6.0.300 [/usr/local/share/dotnet/sdk] jcmac@Jesses-MacBook-Pro % dotnet --version 6.0.300

I can't get any project to work with it. They all work with VS 2022 and Rider. I even put my MB back to factory settings for an unrelated issue and then installed VS 2022 and it still won't. useModerNet is set to true.

I've symlinked sudo ln -s /usr/local/share/dotnet /usr/local/bin/

Not sure where to go from here. The startup limit is set to 180 secs.

I'd appreciate any help you have! Thanks. Oh and I just tried the beta version of omnisharp to see if that would do anything. I'm on VS Code prerelease and regular VS Code, which both are up to date.

JoeRobich commented 2 years ago

@jcoble If you set the Omnisharp LogLevel to trace in VS Code Settings, are there additional details logged to the OmniSharp Log?

jcoble commented 2 years ago

@JoeRobich Ya, I'm still getting the same error. Nothing added onto it to give anymore clue into what it could be.

Starting OmniSharp server at 6/17/2022, 12:27:34 PM Target: /Users/jcmac/mainrepos/trackmyhealthmicro/api/trackmyhealthmicro.sln

OmniSharp server started with .NET 6.0.300 . Path: /Users/jcmac/.vscode-insiders/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.1-beta.2-net6.0/OmniSharp.dll PID: 59382

[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

nenright commented 2 years ago

not sure if its related or not but I'm seeing this upon installing the extension:

Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'. An attempt was made to load a program with an incorrect format.

harry-patel-jisc commented 2 years ago

i'm getting this too

Starting OmniSharp server at 28/06/2022, 20:50:55
    Target: /Users/harry-patel/Documents/github/jisc/Hesa-Data-Iris/Hesa.Iris.sln

OmniSharp server started with .NET 6.0.300
.
    Path: /Users/harry-patel/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll
    PID: 93383

Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/harry-patel/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'. An attempt was made to load a program with an incorrect format.

File name: '/Users/harry-patel/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'
[ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).
harry-patel-jisc commented 2 years ago

downgrading to v1.24.4 worked for me

jcoble commented 2 years ago

@harry-patel-jisc Hey! That worked!!!! Finally. Not sure what happened in the latest build but at least it's working now. Thanks Harry!!

JoeRobich commented 2 years ago

@harry-patel-jisc The error you are seeing typically occurs when you have an x64 build of the .NET SDK installed instead of arm64. To use 1.25.0 you should uninstall your x64 SDK and install the arm64 version.

jcoble commented 2 years ago

I have the arm64 version installed. I used visual studio 2022 preview to get everything installed correctly in order to use .net MAUI. I even reformatted back to factory a month back on unrelated issue. I can try again, but there's no way I would be able to do all the other .net 6 things I do especially in Rider. I've never had an error saying I have x64 version installed. I do know that if I had installed the x64 version first a while ago, then installed the arm version, you're supposed to clear both them out then install the arm version.

Runtime Environment: OS Name: Mac OS X OS Version: 12.4 OS Platform: Darwin RID: osx.12-arm64 Base Path: /usr/local/share/dotnet/sdk/6.0.301/

Host (useful for support): Version: 6.0.6 Commit: 7cca709db2

.NET SDKs installed: 6.0.300 [/usr/local/share/dotnet/sdk] 6.0.301 [/usr/local/share/dotnet/sdk]

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

❯ dotnet --list-sdks 6.0.300 [/usr/local/share/dotnet/sdk] 6.0.301 [/usr/local/share/dotnet/sdk]

❯ dotnet --list-runtimes Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

❯ dotnet --version 6.0.301

if you see something off here though please let me know. image

image

Some of these settings I played around with. But I have Rider and VS 2022 preview and am able to create .net MAUI projects along with other .net core solutions, etc. But, I could always be wrong, and I'd sure be mad at myself if I were. Lol

JoeRobich commented 2 years ago

@jcoble Sorry, yes it appears you are in a different boat. I was speaking to the An attempt was made to load a program with an incorrect format. message in @harry-patel-jisc's omnisharp log.

Looking at your settings nothing jumps out as being problematic. Can you tell me more about the particular project that is failing to load? Is it a MAUI project? If you create a new console app, does the C# extension load when opening it?

jcoble commented 2 years ago

@JoeRobich No Worries, so I tried a number of different locations and ways of inputing the sdk location in but now am getting errors! So that helps. (That was after I re-upgraded to the latest version of omni.)

I think this is related to the single quotes not being stripped away like another user https://github.com/OmniSharp/omnisharp-roslyn/issues/2412#issuecomment-1163382432

(this is where I originally had it and think this is correct)

/usr/local/share/dotnet/sdk/6.0.301/

image

(I changed it to here after looking vs 2022's settings)

image

Starting OmniSharp server at 6/28/2022, 10:24:58 PM Target: /Users/jcmac/Projects/testconsole/testconsole.sln

OmniSharp server started with .NET 6.0.301 (/usr/local/share/dotnet/dotnet). Path: /Users/jcmac/.vscode-insiders/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 85205

    Assembly loaded: OmniSharp.DotNetTest
    Loaded OmniSharp.DotNetTest, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.Host
    Loaded OmniSharp.Host, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.MSBuild
    Loaded OmniSharp.MSBuild, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.Roslyn
    Loaded OmniSharp.Roslyn, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.Roslyn.CSharp
    Loaded OmniSharp.Roslyn.CSharp, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.Script
    Loaded OmniSharp.Script, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded: OmniSharp.Shared
    Loaded OmniSharp.Shared, Version=1.39.0.0, Culture=neutral, PublicKeyToken=7e5bf7b3b470b509
    Assembly loaded from path: /Users/jcmac/.vscode-insiders/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.razor/OmniSharpPlugin/Microsoft.AspNetCore.Razor.OmniSharpPlugin.dll
    Starting OmniSharp on Unknown 0.0 (Unknown)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    .NET SDK requires MSBuild instances version 17.0.0 or higher

Could not locate MSBuild instance to register with OmniSharp. [ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

But I'm pretty sure the way I had it originally was correct

Sorry, meant to say that I was using a console app made from vs 2022 to test with. And i just went back to the omnisharp last release and everything is working again.

JoeRobich commented 2 years ago

@jcoble You should not have to enter the sdkPath or sdkVersion unless you want to use a SDK not discoverable from your PATH. If you clear that configuration, is it able to locate your installed SDKs?

I think this is related to the single quotes not being stripped away like another user https://github.com/OmniSharp/omnisharp-roslyn/issues/2412#issuecomment-1163382432

The issue is with the setting descriptions. Let me remove the quotes from the recommended values as they were not intended to part of the value.

anhhtca commented 2 years ago

downgrading to v1.24.4 worked for me

Tell me how to downgrade, please ? Thanks !

jcoble commented 2 years ago

downgrading to v1.24.4 worked for me

Tell me how to downgrade, please ?

Thanks !

Just go to your extensions, find omnisharp, then hit the little gear icon and select install another version(I think that's what it's called). You will see a list of previous versions and just hit 1.24.4. Then reload VS once complete. And that's it. I immediately saw it start to work the logs after I downgraded.

anhhtca commented 2 years ago

downgrading to v1.24.4 worked for me

Tell me how to downgrade, please ? Thanks !

Just go to your extensions, find omnisharp, then hit the little gear icon and select install another version(I think that's what it's called). You will see a list of previous versions and just hit 1.24.4. Then reload VS once complete. And that's it. I immediately saw it start to work the logs after I downgraded.

It 's worked. Thanks so much !

br-reinaldo-pires commented 2 years ago

downgrading to v1.24.4 worked for me

It worked for me as well. Thanks!

anup-shetty commented 2 years ago

downgrading to v1.24.4 worked for me

Worked for me as well.

rking-bennie commented 2 years ago

downgrading to v1.24.4 worked for me

proof all heros dont wear capes!

sihbher commented 2 years ago

downgrading to v1.24.4 worked for me

It worked for me as well!!!

So, it is a bug in the extension right?

filipw commented 2 years ago

If you get the System.BadImageFormatException it typically means you have an x64 emulated dotnet installed of the native arm64 variant. You should make sure that you install the correct dotnet for your architecture, that arm64 dotnet is accessible from the Code terminal, and then remove the extension and reinstall again to force it to reacquire all the assets.

sihbher commented 2 years ago

If you get the System.BadImageFormatException it typically means you have an x64 emulated dotnet installed of the native arm64 variant. You should make sure that you install the correct dotnet for your architecture, that arm64 dotnet is accessible from the Code terminal, and then remove the extension and reinstall again to force it to reacquire all the assets.

At least it's not my case, or so it seems from the terminal. In addition to that if I do the downgrade as recommended, the extension works, not so in the latest version

dotnet info
JoeRobich commented 2 years ago

@sihbher It could also mean you have the Universal install of VS Code which runs as x64 on Rosetta. This means using the arm64 SDK would throw a BadImageFormatException. I would suggest uninstalling VS Code and be sure to click Apple Silicon when downloading VS Code again (download page).

image
hoangvp-gearinc commented 2 years ago

downgrading to v1.24.4 worked for me

Tell me how to downgrade, please ? Thanks !

Just go to your extensions, find omnisharp, then hit the little gear icon and select install another version(I think that's what it's called). You will see a list of previous versions and just hit 1.24.4. Then reload VS once complete. And that's it. I immediately saw it start to work the logs after I downgraded.

It worked, thanks

b5stephen commented 2 years ago

While I use an M1 Mac, I have to run the x64 version of DotNet due to certain project dependencies not yet supporting ARM.

Downgrading to v1.24.4 worked for me

seilorjunior commented 2 years ago

Same issue here, with v1.24.4 worked

adamholthaus50 commented 1 year ago

Same issue for me on the Mac M1 using 64 arm version. Downgrade to 1.24.4 seems to have fixed it.

gestj commented 1 year ago

Same here ... Mac M1, 64arm + downgrade to 1.24.4 worked.

MadMacMad commented 1 year ago

Same here ... Mac M1, 64arm + downgrade to 1.24.4 worked.

RbBtSn0w commented 1 year ago

Same here.

Mac M1 Pro

VSCode: 1.74.0 (Universal)

image

    Starting OmniSharp on Unknown 0.0 (Unknown)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is ''7.0.100''. Please update your settings and restart OmniSharp.
    The Sdk path specified in the OmniSharp settings does not exist. Configured path is ''/usr/local/share/dotnet/sdk/7.0.100''. Please update your settings and restart OmniSharp.
    Located 0 MSBuild instance(s)

[STDERR] Could not locate MSBuild instance to register with OmniSharp.

RbBtSn0w commented 1 year ago

Same here.

Mac M1 Pro

VSCode: 1.74.0 (Universal)

image

Starting OmniSharp on Unknown 0.0 (Unknown) info: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK info: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [fail]: OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is ''7.0.100''. Please update your settings and restart OmniSharp. [fail]: OmniSharp.MSBuild.Discovery.Providers.SdkOverrideInstanceProvider The Sdk path specified in the OmniSharp settings does not exist. Configured path is ''/usr/local/share/dotnet/sdk/7.0.100''. Please update your settings and restart OmniSharp. info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 0 MSBuild instance(s) [STDERR] Could not locate MSBuild instance to register with OmniSharp.

By the way, find other way.

workaround:

✅ download this extension version: 1.24.4

RbBtSn0w commented 1 year ago

Same here. Mac M1 Pro VSCode: 1.74.0 (Universal) image Starting OmniSharp on Unknown 0.0 (Unknown) info: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK info: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. info: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [fail]: OmniSharp.MSBuild.Discovery.Providers.SdkInstanceProvider The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is ''7.0.100''. Please update your settings and restart OmniSharp. [fail]: OmniSharp.MSBuild.Discovery.Providers.SdkOverrideInstanceProvider The Sdk path specified in the OmniSharp settings does not exist. Configured path is ''/usr/local/share/dotnet/sdk/7.0.100''. Please update your settings and restart OmniSharp. info: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 0 MSBuild instance(s) [STDERR] Could not locate MSBuild instance to register with OmniSharp.

By the way, find other way.

workaround:

✅ download this extension version: 1.24.4

Why have this bug? the refactor base dependency.

detail here(On 1.25.0 above)

https://github.com/OmniSharp/omnisharp-vscode/issues/5120

shpsyte commented 1 year ago

That's right!

People are downgrading right away, but actually they should installed the right architecture for mac M1 Silicon chip

Arm64 for .net + vscode silicon will work fine

allisonchou commented 1 year ago

Oops - instinctively closed this issue since I thought it was Razor specific. Re-opened. 😄

sigespweb22 commented 1 year ago

downgrading to v1.24.4 worked for me

davemjones commented 1 year ago

I fought with this for several days. Everything worked great on my Intel MacBook Pro but not on my M1 MacBook Pro. The one change I made that seemed to make the difference was specifying the Omnisharp: Sdk Path in your VSCode settings. I set mine to /usr/local/dotnet

alexmarmon commented 1 year ago

Switching to the new c# extension from Microsoft is another option for anyone hitting this still. https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit

ugumerie commented 1 year ago

Switching to the new csdevkit would work but the roslyn analyzers stopped working.