vscode-csharp
vscode-csharp copied to clipboard
System.BadImageFormatException: Could not load file or assembly '/Users/xxxx/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll
Environment data
dotnet --info
output:
.NET SDK (reflecting any global.json):
Version: 6.0.301
Commit: 43f9b18481
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.301 [/usr/local/share/dotnet/sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
VS Code version: 1.69 C# Extension version: 1.25
OmniSharp log
Starting OmniSharp server at 7/12/2022, 10:44:02 AM Target: /Users/xxxx/..../.../..../project.sln
OmniSharp server started with .NET 6.0.301 . Path: /Users/xxxx/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 95021
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/xxxx/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'. An attempt was made to load a program with an incorrect format.
File name: '/Users/xxxx/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.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).
Steps to reproduce
- Open VS Code
- Open a .NET project
- Wait for Omnisharp to display the error in the Output tab of the integrated terminal
Expected behavior
Should not receive the error
Actual behavior
Receive the error above.
Additional context
I'm running on a Mac 2021 with the M1 chip.
To make sure I was running the arm64 version of the .NET run times: I removed the .NET installations Uninstalled the C# VS Code extension Reinstalled the .NET SDK and runtimes for Arm64 using the dotnet-sdk-6.0.301-osx-arm64.pkg installer Made sure the arm64 dotnet path was included in the $PATH environment variable Reinstalled the C# and other .NET extensions from the .NET Core Extension Pack
@roger-cprops It appears that you have the Universal or Intel build of VSCode installed. I recommend uninstalling VS Code and installing the Apple Silicon build. https://code.visualstudio.com/Download

Thanks.
I downloaded and installed the Apple Silicon app and it's the same so I'm still getting the error. Version: 1.69.1 (Universal) Commit: b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a Date: 2022-07-12T08:21:51.333Z Electron: 18.3.5 Chromium: 100.0.4896.160 Node.js: 16.13.2 V8: 10.0.139.17-electron.0 OS: Darwin arm64 21.5.0
Version: 1.69.1 (Universal)
This line shows that the universal build of VS Code is running. Not sure if there are somehow multiple copies installed or whether you need to quit out of VS Code and restart.
@JoeRobich I redownloaded VS Code and I'm still getting the same error: Version: 1.69.1 Commit: b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a Date: 2022-07-12T08:22:10.822Z Electron: 18.3.5 Chromium: 100.0.4896.160 Node.js: 16.13.2 V8: 10.0.139.17-electron.0 OS: Darwin arm64 21.5.0
Can you share the error from the OmniSharp Log?
Sure. It's the same error as above:
OmniSharp server started with .NET 6.0.301 . Path: /Users/rogerhopkins/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 56050
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/rogerhopkins/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'. An attempt was made to load a program with an incorrect format.
File name: '/Users/rogerhopkins/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.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).
I finally got this resolved. I had to manually delete this file: .vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-x64/.omnisharp/1.39.0-net6.0/OmniSharp.dll
I then reinstalled the C# extension and got past the error.
Apparently when you uninstall the extension it doesn't delete this file so it was always using the x64 version even after a reinstall.
I'm experiencing the same problem:
Starting OmniSharp server at 9/21/2022, 2:28:48 AM
Target: /Users/rob/Code/SomeProject/SomeSolution.sln
OmniSharp server started with .NET 6.0.201
.
Path: /Users/rob/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll
PID: 83254
Unhandled exception. System.BadImageFormatException: Could not load file or assembly '/Users/rob/.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.
Deleting the entire folder (rm -rf ms-dotnettools.csharp-1.25.0-darwin-arm64
) and reinstalling the c# extension didn't help.
@RobThree It may indicate that you have the VS Code Universal Mac installed. This version runs under Rosetta as x64 for some reason and would have load failures with native binaries. I would recommend uninstalling and download the Apple Silicon build of VS Code.
I had the same error on Windows x64. Somehow the 32-bit version of the C# extension got installed. Once I removed that extension folder and re-installed, this error went away. I have no idea how the 32-bit version of the extension got installed.
For those of you on Silicon (M1/M2/etc.) Macs having this issue, these are the steps that solved it for me:
(BE SURE THAT YOU HAVE THE ARM64 .NET ARCHITECTURE INSTALLED)
1. Be sure that you have the Apple Silicon version of Visual Studio Code installed (and not the Universal build).
-
Open VS code
-
Click Code on the menu bar and then select About Visual Studio Code
-
The version info should look something like the following, you really just want to make sure that you don't see (Universal) next to the version number.
-If you see (Universal) next to the version number, uninstall/delete your current version of Visual Studio Code
-Then, follow this link and select the Apple Silicon version of Visual Studio Code and install it with your preferred method.
2. Reinstalling the C# extension
- If you've already installed the C# extension on the Universal build of Visual Studio Code, there seems to be a problem if you just try to re-install it.
-To solve this problem go to the root of your computer (normally named Macintosh HD) and press CMD+SHIFT+PERIOD to reveal hidden files in your finder
-Then follow the path Users/{YOUR_USERNAME}/.vscode/extensions/ and look for a file called ms-dotnettools.csharp-{VERSION_NUMBER}-darwin-x64
-Delete the folder entirely and then open VS Code again and look up the C# Extenstion and re-install
-If you look for the same folder it should be replaced by a file called ms-dotnettools.csharp-{VERSION_NUMBER}-darwin-arm64 which should be compatible with your Mac's chip.
That solved the problem for me and hopefully, this helps if you had issues as well.
Happy coding!