skip to Main Content

I’ve been having a hard time running dotnet commands on an existing dotnet 6 application, on my m1 mac. I seem to have made it worse by downloading the dotnet SDK 6.0.401 in arm64 version, which has caused this error as soon as I open the project in vs code:

Starting OmniSharp server at 9/25/2022, 4:57:13 PM
Target: /Users/benjamin/dev/vepo_back_end/Vepo.sln

OmniSharp server started with .NET 6.0.401 .
Path: /Users/benjamin/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll
PID: 59074

Unhandled exception. System.BadImageFormatException: Could not load
file or assembly
‘/Users/benjamin/.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/benjamin/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll’

I have redownloaded the x86 version and reinstalled C# in vscode extensions but I still get the same error. What should I do?

UPDATE: Ive now successfully run dotnet commands and even ran the app. I still have the same error message when I open vs code though, so I still have the problem but it is not preventing me doing anything.

6

Answers


  1. Chosen as BEST ANSWER

    In my case just reverting the C# vscode extension to version 1.24.4 fixed it.

    Actually, the issue with the version only exists for people with x64 .net sdk installed on an m1 mac. . Reveerting the C# vscode extension, or downloading the arm64 .net sdk should work (and I reverted the C# vscode extension).


  2. I had the same errors using dotnet 6.0.x SDK and VSCode on my M1 Mac. VSCode would not run the C# debugger with the same error. I checked in the File > About VSCode menu item and was running the x64 version of VSCode. I uninstalled VSCode and then re-installed with the universal installer and it now shows the Universal installation. This resolved the error for me.

    Login or Signup to reply.
  3. I got the same problem, I installed .NET 6.0.401 from Microsoft packages but the issue still happened.

    It turned out VSCode was using x64 version which was installed previously, not arm64 one. It seems the installer didn’t relocate my dotnet command. I re-create the dotnet link to correct arm64 one and the error was gone.

    Login or Signup to reply.
  4. Would you by accident have the setting omnisharp.useModernNet set to false? Or have any omnisharp. setting with mono or path or sdk in it?

    If so, try removing all of them. And maybe setting omnisharp.useModernNet explicitly to true (it should be the default).

    If this fails, try:

    • Removing and reinstalling the extension
    • Setting "omnisharp.path": "latest"
    Login or Signup to reply.
  5. I faced a similar issue. I hope this solution works.

    My solution was

    Extension -> Settings (wheel symbol) -> Install Another Version… -> 1.24.4

    Basically, I downgraded the version of the C# extension.

    Login or Signup to reply.
  6. On Windows I had the same problem with dotnet x86 and x64 incompatibility. I have 32-bit vscode installed, which installs ms-dotnettools.csharp-1.25.2-win32-ia32, which downloads that x86 version of Omnisharp. But I had C:Program Filesdotnet before C:Program Files (x86)dotnet on my PATH, so when the vscode extension ran dotnet the x64 version was found, which failed.

    The fix was to move C:Program Files (x86)dotnet to be before the x64 dotnet on my PATH, either temporarily on the command line, or in the system environment variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search