vscode-csharp
vscode-csharp copied to clipboard
Allow acquiring x64 .NET 6.0 OmniSharp on an arm64 machine
When I set "omnisharp.useModernNet": true, and restart VS Code I get an error:
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/meligy/.vscode-insiders/extensions/ms-dotnettools.csharp-1.24.0/.omnisharp/1.38.1-beta.63-net6.0/OmniSharp.dll'. An attempt was made to load a program with an incorrect format.
This is in VS Code Insiders but I don't think it makes a difference. Because I checked the path and the path does exist.
Note also that the error is not about missing file or permissions, but a program with an incorrect format.
I tried removing the folder and reinstalling the extension, which downloaded it again, but then showed the same error.
I tried adding/removing "omnisharp.path": "latest", but it doesn't seem to help.
This is observed in Omnisharp 1.24.0. Running on macOS Monterey 12.1 (21C52), on an M1Max MacBook Pro 16 2021.
Update
This seems to happen when running macOS on an ARM machine and using x64 .NET SDK (see comments below).
Also worth noting that I tried with both ARM and x64 versions of .NET 6.
At first I thought the problem might be that the x64 version of .NET was the one coming in the PATH (I needed that for a .NET 5 project and only x64 .NET CLI can handle older SDKs). But removing this and ensuring that the dotnet command resolves to the ARM version did not fix it either.
Sorry, I forgot that I also had "omnisharp.dotnetPath": "/usr/local/share/dotnet/x64",.
When I removed this, the error was gone.
Although in my .NET 5 project I got this instead:
[ERROR] Error: Found dotnet version 5.0.404. Minimum required version is 6.0.100.
Which I totally understand might not be a supported scenario, so that's fine (although of course I'd have loved to be able to use it!).
This makes the original issue specific to x64 dotnet running on ARM macOS (I updated the issue text to reflect this).
I think what you are running into is that VS Code acquires ARM64 build of OmniSharp but you want x64. There is currently no way to control this from the extension.
Once you use updated the path to use ARM .NET SDK things would work, however you need to have .NET 6 ARM64 SDK and it seems you only have 5 (or global.json restricts it).
However this is not an issue for the server, but for the extension which should allow obtaining a different architecture build of O#, so I will move it.
A note to @333fred who implemented this feature. It might be nice to be able to set the preferred rid as a separate setting that would override whatever is inferred.
While we could implement something like that, I wouldn't really want to encourage it. The ARM version will be significantly better on ARM devices than the x64 version will be.
I think in a way this is also temporary. .NET 6 completely changed how dotnet SDKs are reasoned about on ARM machines (installation paths and so on). This requires a clean set up to be done by the developers which I understand plenty of people have not done and are still in the emulation world using the old x64 SDKs.
This issue still open so people using another client (such as vim) and searching for same problem most likely first hit the this issue, Even in vs-code this it been patched problem it still persist in omnisharp server (I might be wrong since don't know the exact source of the problem) at least for M1 macs but anyways this dirty workaround I listed below should work in any cases or clients
Workaround was:
- go to dotnet-sdk folder there should be both x64 and arm64
- rename x64 to x64.backup or something else
- use symlink to arm64 folder like
ln -sf /usr/local/share/dotnet/arm64 x64 - run OmniSharp and it should work
I needed to be able to run and debug an x64 application on m2 mac from VS Code and this is what worked for me. I had a completely fresh system and took the following steps:
- install ARM sdk
- install x64 sdk (in this specific order)
- use
/usr/local/share/dotnet/x64/dotnetfor PATH env. variable, I've set it directly in/etc/paths.d/dotnetfile - run
sudo ln -s /usr/local/share/dotnet/x64/dotnet /usr/local/bin/to create symlink - add
export DOTNET_ROOT="/usr/local/share/dotnet/x64/dotnet/"to .zprofile in your user folder - in settings.json for VS Code
"omnisharp.dotnetPath": "/usr/local/share/dotnet", "omnisharp.sdkVersion": "6.0.408" - in launch.json for launch task as well as for debugger attach task add
"targetArchitecture": "x86_64"
With this configuration I'm able to use latest OmniSharp targeting ARM and run and debug a .Net 6 x64 application. So OmniSharp runs natively and application runs using Rosetta. The only drawback is that this configuration is system-wide. I wasn't able to find a solution to configure it only for a workspace/project