godot icon indicating copy to clipboard operation
godot copied to clipboard

Godot 4 .NET not building on Windows Arm64

Open Fabian-Internet opened this issue 10 months ago • 5 comments

Tested versions

  • Version 4.2.2

System information

Godot v4.3.dev5.mono - Windows 10.0.22631 - Vulkan (Mobile) - ANGLE (Qualcomm, Qualcomm(R) Adreno(TM) 680 GPU (0x41333430) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.2020.0) () - Microsoft SQ2 @ 3.15 GHz (8 Threads) (SurfaceX)

Issue description

I have a Surface Pro X running Windows 11 Home (23H2) on the Microsoft SQ2 @ 3.15 GHz, which is a 64-bit operating system, ARM-based processor. When I try to build on this device inside the Godot engine (v. 4.2/4.3), I get the following error inside the editor:

The build method threw an exception. System.BadImageFormatException: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Format of the executable (.exe) or library (.dll) is invalid. (0,0)

and this error inside the console:

Found .NET Sdk version '8.0.203': C:\Program Files\dotnet\sdk\8.0.203
ERROR: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neut.
File name: 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFo.
File name: 'C:\Program Files\dotnet\sdk\8.0.203\Microsoft.Build.dll'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>g__TryLoadAssembly|1(AssemblyNa)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>b__0(AssemblyLoadContext assemb)
   at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, Assemb)
   at GodotTools.ProjectEditor.ProjectUtils.Open(String path)
   at GodotTools.GodotSharpEditor.ApplyNecessaryChangesToSolution() in /root/godot/modules/mono/editor/GodotTools/Godot5
   at: void GodotTools.GodotSharpEditor.ApplyNecessaryChangesToSolution() (/root/godot/modules/mono/editor/GodotTools/G)

I have the strong suspicion that this is caused because Godot is trying to load the wrong architecture type of the dll(s), but I do not know how to fix this.

The building using Visual Studio directly works on this device (the Arm64 Surface) and the building of the project inside the Godot editor works on my normal x64 Windows desktop PC.

Note: I have the sdk installed and building works using Visual studio.

PS C:\Users\fabian> Get-ItemProperty "C:\Program Files\dotnet\sdk\8.0.203\Microsoft.Build.dll"
    Directory: C:\Program Files\dotnet\sdk\8.0.203
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        05.03.2024     23:45        5568688 Microsoft.Build.dll
PS C:\Users\fabian> dotnet --version
8.0.203
PS **C:\Users\fabian>

Steps to reproduce

  • Click on build

Minimal reproduction project (MRP)

N/A, any mono project using a c# script

Fabian-Internet avatar Apr 22 '24 16:04 Fabian-Internet

I have the strong suspicion that this is caused because Godot is trying to load the wrong architecture type of the dll(s)

I think so too. Do you have other .NET SDKs installed for other architectures? Can you share the output of the dotnet --info command? It should show more information about your setup, like other SDK installations, information about the .NET runtime being used, and other environment information that could be useful to diagnose what's happening.

Also, make sure the Godot installation matches the architecture of the .NET SDK. It doesn't look like we distribute Windows builds of Godot for the ARM architecture, so I assume this is a custom build.

raulsntos avatar Apr 22 '24 17:04 raulsntos

This happens on non ARM architectures too. For instance, when you have both an x86 and an x64 .NET installation (IIRC VS does that by default), and your PATH is set to prioritize the wrong one. I've been meaning to see if we could do something about it for some time now, but never got to tackle it yet.

paulloz avatar Apr 22 '24 17:04 paulloz

I accidentally clicked the button sorry

@raulsntos the info command gives this output:

PS C:\Users\fabian> dotnet --info
.NET SDK:
 Version:           8.0.204
 Commit:            c338c7548c
 Workload version:  8.0.200-manifests.7d36c14f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-arm64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.204\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.4
  Architecture: arm64
  Commit:       2d7eea2529

.NET SDKs installed:
  6.0.421 [C:\Program Files\dotnet\sdk]
  7.0.118 [C:\Program Files\dotnet\sdk]
  7.0.408 [C:\Program Files\dotnet\sdk]
  8.0.104 [C:\Program Files\dotnet\sdk]
  8.0.202 [C:\Program Files\dotnet\sdk]
  8.0.204 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x64   [C:\Program Files\dotnet\x64]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
PS C:\Users\fabian>

And the arm version of Windows can run most x64 Programs (even games) just fine, and also the Godot editor x64 build works without problems on this device. The building is the only thing not working.

Fabian-Internet avatar Apr 22 '24 18:04 Fabian-Internet

Ah, so you are using the x64 editor build. I think that may be the problem, the architecture of the Godot editor needs to match the architecture of the .NET SDK that you installed (which seems to be arm64).

Since you also seem to have the x64 .NET SDK, you can try prioritizing that one in your PATH environment variable (like @paulloz suggested) and setting the DOTNET_ROOT environment variable to that path (C:\Program Files\dotnet\x64) and see if that works.

Just to be clear, I think the problem is mixing programs of different architectures together. Using all x64 or all arm64 programs should probably work but they all have to match.

raulsntos avatar Apr 23 '24 01:04 raulsntos

I've now tried setting the environment variables, but it did not fix the issue. Is there a way to provide official arm builds for windows?

Fabian-Internet avatar Apr 24 '24 06:04 Fabian-Internet

Would also love to see official builds for Windows ARM64.

I think this is going to be more common with the Snapdragon X starting to show up in devices.

TranquilMarmot avatar May 20 '24 18:05 TranquilMarmot

+1: would love to see ARM64 support since Microsoft is investing heavily into the ARM64 architecture.

DamionGans avatar May 24 '24 13:05 DamionGans

waiting for official Windows on Arm builds

zjw1918 avatar Jun 18 '24 02:06 zjw1918

Official Windows ARM support is tracked by https://github.com/godotengine/godot-proposals/issues/2408. Go add a thumbs up :+1: if you are interested.

raulsntos avatar Jun 18 '24 04:06 raulsntos