dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 654 forks source link

Unhandled exception. System.BadImageFormatException #5224

Closed StacyCMay closed 2 years ago

StacyCMay commented 2 years ago

Issue Description

Unhandled exception. System.BadImageFormatException

Steps to Reproduce

Upgraded to version 1.25.0

Expected Behavior

CSharp extension loads without error

Actual Behavior

Unhandled exception. System.BadImageFormatException Could not load file or assembly '~/.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.

Logs

OmniSharp log

C# log

Starting OmniSharp server at 5/24/2022, 4:11:22 PM Target: ~/Documents/Corporate/Clients/Tantus/PCL/JSI/Repos/JSIv2Platform-Deploy/Solutions/JSI.Core/JSI.Core.sln OmniSharp server started with .NET 6.0.300 . Path: ~/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll PID: 10191 Unhandled exception. System.BadImageFormatException: Could not load file or assembly '~/.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: '~/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/.omnisharp/1.39.0-net6.0/OmniSharp.dll'

Environment information

VSCode version: 1.67.2 C# Extension: 1.25.0

Mono Information OmniSharp using mono :6.12.0
Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.300 Commit: 8473146e7d Runtime Environment: OS Name: Mac OS X OS Version: 12.4 OS Platform: Darwin RID: osx.12-x64 Base Path: /usr/local/share/dotnet/x64/sdk/6.0.300/ Host (useful for support): Version: 6.0.5 Commit: 70ae3df4a6 .NET SDKs installed: 3.1.416 [/usr/local/share/dotnet/x64/sdk] 3.1.417 [/usr/local/share/dotnet/x64/sdk] 3.1.418 [/usr/local/share/dotnet/x64/sdk] 3.1.419 [/usr/local/share/dotnet/x64/sdk] 5.0.404 [/usr/local/share/dotnet/x64/sdk] 5.0.405 [/usr/local/share/dotnet/x64/sdk] 5.0.406 [/usr/local/share/dotnet/x64/sdk] 5.0.407 [/usr/local/share/dotnet/x64/sdk] 5.0.408 [/usr/local/share/dotnet/x64/sdk] 6.0.101 [/usr/local/share/dotnet/x64/sdk] 6.0.102 [/usr/local/share/dotnet/x64/sdk] 6.0.103 [/usr/local/share/dotnet/x64/sdk] 6.0.104 [/usr/local/share/dotnet/x64/sdk] 6.0.105 [/usr/local/share/dotnet/x64/sdk] 6.0.300 [/usr/local/share/dotnet/x64/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.22 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.23 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.24 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.25 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.14 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.15 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.16 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.22 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.23 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.24 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.25 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.14 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.15 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.16 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |angular-console|nrwl|17.17.0| |angular-essentials|johnpapa|13.0.0| |Angular2|johnpapa|13.0.0| |application-insights|VisualStudioOnlineApplicationInsights|0.4.2| |argutec-azure-repos|argutec|1.2007.15| |armview|bencoleman|0.4.6| |azure-account|ms-vscode|0.10.1| |azure-event-hub-explorer|Summer|0.1.1| |azure-iot-edge|vsciot-vscode|1.25.9| |azure-iot-toolkit|vsciot-vscode|2.16.6| |azure-iot-tools|vsciot-vscode|0.3.0| |azure-pipelines|ms-azure-devops|1.205.0| |azure-storage-explorer|formulahendry|0.1.2| |azurecli|ms-vscode|0.5.0| |azurerm-vscode-tools|msazurermtools|0.15.7| |csharp|ms-dotnettools|1.25.0| |data-workspace-vscode|ms-mssql|0.2.0| |debugger-for-edge|msjsdiag|1.0.15| |EditorConfig|EditorConfig|0.16.4| |jupyter|ms-toolsai|2022.4.1021342353| |jupyter-keymap|ms-toolsai|1.0.0| |jupyter-renderers|ms-toolsai|1.0.6| |material-icon-theme|PKief|4.17.0| |msbuild-project-tools|tintoy|0.4.3| |mssql|ms-mssql|1.14.2| |ng-template|Angular|13.3.4| |powershell|ms-vscode|2022.5.1| |prettier-vscode|esbenp|9.5.0| |python|ms-python|2022.6.2| |remote-containers|ms-vscode-remote|0.234.0| |remote-ssh|ms-vscode-remote|0.80.0| |remote-ssh-edit|ms-vscode-remote|0.80.0| |remote-wsl|ms-vscode-remote|0.66.3| |rest-client|humao|0.24.6| |sql-database-projects-vscode|ms-mssql|0.16.2| |svn-scm|johnstoncode|2.15.5| |vscode-ai|ms-toolsai|0.10.0| |vscode-ai-remote|ms-toolsai|0.12.0| |vscode-apimanagement|ms-azuretools|1.0.3| |vscode-azureappservice|ms-azuretools|0.24.0| |vscode-azurefunctions|ms-azuretools|1.7.0| |vscode-azureresourcegroups|ms-azuretools|0.5.0| |vscode-azurestorage|ms-azuretools|0.14.0| |vscode-azurevirtualmachines|ms-azuretools|0.6.0| |vscode-bicep|ms-azuretools|0.6.18| |vscode-cosmosdb|ms-azuretools|0.19.0| |vscode-docker|ms-azuretools|1.22.0| |vscode-dotnet-runtime|ms-dotnettools|1.5.0| |vscode-eslint|dbaeumer|2.2.2| |vscode-iot-device-cube|vsciot-vscode|0.3.0| |vscode-iot-workbench|vsciot-vscode|0.16.0| |vscode-logicapps|ms-azuretools|1.1.6| |vscode-node-azure-pack|ms-vscode|0.3.0| |vscode-npm-script|eg2|0.3.25| |vscode-openapi|42Crunch|4.9.5| |vscode-peacock|johnpapa|4.0.1| |vscode-pylance|ms-python|2022.5.2| |vscode-remote-extensionpack|ms-vscode-remote|0.21.0| |vscode-yaml|redhat|1.7.0| |vscodeintellicode|VisualStudioExptTeam|1.2.21| |winteriscoming|johnpapa|1.4.4|;
StacyCMay commented 2 years ago

Reverting to 1.24.4 works.

JoeRobich commented 2 years ago

@StacyCMay This likely means that you have the x64 build of the .NET SDK installed. If you uninstall and install the arm64 instead, it should start up fine. Sorry for the inconvenience.

vudzero commented 2 years ago

I can confirm that we must revert back to 1.24.4 if on a MacOS with M1 arm64 CPU and x64 dotnet SDK installed

ElDuderini commented 2 years ago

I can confirm that we must revert back to 1.24.4 if on a MacOS with M1 arm64 CPU and x64 dotnet SDK installed

This worked for me too, thanks!

filipw commented 2 years ago

I will close this because it is the expected behavior.

Having just the emulated x64 on arm64 is not the supported scenario by OmniSharp. However, you can first install arm64 dotnet, and then install x64 dotnet in which case, dotnet installer places it under the x64 folder:

In this case you could always toggle to x64 by running e.g. export PATH=/usr/local/share/dotnet/x64:$PATH. You can find more here https://github.com/dotnet/designs/blob/main/accepted/2021/x64-emulation-on-arm64/x64-emulation.md

ElDuderini commented 2 years ago

I will close this because it is the expected behavior.

Having just the emulated x64 on arm64 is not the supported scenario by OmniSharp. However, you can first install arm64 dotnet, and then install x64 dotnet in which case, dotnet installer places it under the x64 folder:

* `/usr/local/share/dotnet` is now your (default) arm64 dotnet

* `/usr/local/share/dotnet/x64` is now your x64 dotnet

In this case you could always toggle to x64 by running e.g. export PATH=/usr/local/share/dotnet/x64:$PATH. You can find more here https://github.com/dotnet/designs/blob/main/accepted/2021/x64-emulation-on-arm64/x64-emulation.md

Would you happen to know how I would go about setting my default base path to the arm64 SDK? I installed x64 first and I just installed arm64 today but I don't know how I get dotnet linked to that new SDK. When I type in dotnet --info it still gives me information about the old x64 SDK with the incorrect base path.

filipw commented 2 years ago

This is mostly outlined here by Rich https://github.com/dotnet/sdk/issues/22380#issue-1039006924 Ideally you would nuke the old x64 installation using

sudo rm -r /usr/local/share/dotnet
sudo rm -r /etc/dotnet

Then you would first install arm64 dotnet as this is the recommended variant for arm devices, and if you still need x64 for some specific reason, you install it second. Then arm64 dotnet is your "main" one, and you can "opt into" x64 by either doing a temporary export, creating a specific alias (such as dotnet64) or a switch dotnet run -a x64

ElDuderini commented 2 years ago

This is mostly outlined here by Rich dotnet/sdk#22380 (comment) Ideally you would nuke the old x64 installation using

sudo rm -r /usr/local/share/dotnet
sudo rm -r /etc/dotnet

Then you would first install arm64 dotnet as this is the recommended variant for arm devices, and if you still need x64 for some specific reason, you install it second. Then arm64 dotnet is your "main" one, and you can "opt into" x64 by either doing a temporary export, creating a specific alias (such as dotnet64) or a switch dotnet run -a x64

Thanks. After reinstalling .net and configuring the settings in vscode to use the right mono path, I got the new version of the plugin to work with unity code.

adamshaylor commented 2 years ago

Using the Arm build isn’t an option for my team. We’re working on a project that relies on PostSharp, which appears to have no intention of supporting Arm. OmniSharp was working for us prior to 1.25.

JoeRobich commented 2 years ago

@adamshaylor We can look at adding an option for Mac users to override the detected architecture. But until a change like that goes in, you have a couple options at this time:

adamshaylor commented 2 years ago

We’re also looking into migrating to PostSharp metalama. It’s not a one-to-one replacement, but if we understand correctly, uses Rosylyn under the hood and therefore in theory would allow us to run .NET natively on Arm architecture if we can port our existing code to use it.

miiik4 commented 2 months ago

If you found this issue by Googling the error message, it might be worth trying out dotnet run -a x64 after installing the x64 version of the SDK you are trying to use. That solved my issue 🙂