Missing something to build C# Godot

Godot Version

Godot v4.3

Question

Hello everyone.

Has someone encountered this problem working in C# Godot v4.3 while generating the c# project?

/root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:13 - System.BadImageFormatException: Could not load file or assembly ‘Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Format of the executable (.exe) or library (.dll) is invalid.
File name: ‘Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ —> System.BadImageFormatException: Could not load file or assembly ‘C:\Program Files (x86)\dotnet\sdk\8.0.403\Microsoft.Build.dll’. Format of the executable (.exe) or library (.dll) is invalid.
File name: ‘C:\Program Files (x86)\dotnet\sdk\8.0.403\Microsoft.Build.dll’
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.gTryLoadAssembly|1(AssemblyName assemblyName)
at Microsoft.Build.Locator.MSBuildLocator.<>cDisplayClass15_0.b0(AssemblyLoadContext assemblyLoadContext, AssemblyName assemblyName)
at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)

It is not letting me generate c# Solution in an empty newly created godot project and I make sure to have also the SDK installed.

Yesterday, I made a software cleaning including old SDKs and other tools I am not using anymore, and after that I make sure to install SDKs needed (the ones indicated in the web), but it seems I am still missing something to make Godot generate the project properly.
Any idea what is going wrong with my setup?

Thanks :slight_smile:

Here is my .csproj file:

<Project Sdk="Godot.NET.Sdk/4.3.0">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

On my system I have dotnet sdk 6.0.414 installed and it works fine.
So you can try to install this version or change the one in the first <TargetFramework> tag

The thing is I can not generate my .csproj. Whenever I try to generate it, it triggers the error I show in the previous post,
My project folder only contains:
project.godot
icon.svg and icon.svg.import
.godot

I have tried to generate the C#project both with an old project and with a recently created project and all of them show the same error.

I guess you already tried reinstalling the dotnet 8 sdk?

Maybe Godot 4.3 is trying to use an sdk version that does not match. You could try to create a [gamename].csproj file and paste a configuration from here, e.g. the one from tshadow999 or this one from me (cleaned up), which targets net 8.0:

<Project Sdk="Godot.NET.Sdk/4.3.0">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
  </PropertyGroup>
</Project>

Yes, I have already tried reinstalling it but it still doesnt work.
I think it could be related with the architecture version I am working on, but I am not sure how to solve it.
I am working with the Godot (Windows - .NET - x86_64), and I have installed both .NET SDK x64 and x86. BUt for some reason my PC is not recognizing the net SDK x64 version. (I had this working before I made a clean up of old software)


If I uninstall SDK x86 version, it is not recognizing the .NET SDK x64 version as installed.
I also have tried to create the .csproj manually and tryint to build it but it still shows these errors.

And at this point I am out of ideas. I am going to try to install .NET SDK 6.0 since th old .csproj I had in my godot projects were pointing to this version, but it is still not the .NET SDK version Godot has in its webpage.

try instal in "C:\Program Files\" instead "C:\Program Files (x86)\"

I’ve already done that. That is the path for the .NET SDK x64 version

MacOS Sequoia 15.2 MacBook Air M1, Godot v4.3.stabe.mono.official, .NET SDKs installed: 6.0.428 8.0.405 9.0.102.

When I restarted my Mac after installing .NET 6 and 9, it just worked when i clicked. Project > Project Tools, C#, Create C# Solution.

Hi,
I’m not sure if you’ve already fixed this problem, but i had the same problem in the version 4.4 (x86_64). This solution worked for me:

Uninstall the x86 (32-bit) version of .NET and all other .NET (x86) installations from your system, including the dotnet application in the Programs (x86) folder.

I believe the issue occurs because your system defaults to using the 32-bit version of .NET instead of the 64-bit version, which is required for Godot. As a result, Godot tries to run with an incompatible 32-bit .NET version.

You can check this by running the following command in CMD:

dotnet --info

At some point in the output, it says:

Host:
  Version:      9.0.3
  Architecture: x86
  Commit:       831d23e561

After uninstalling the (x86) versions, it should instead say:

Host:
  Version:      9.0.3
  Architecture: x64
  Commit:       831d23e561

I believe it’s also possible to change the default path to the x64 version in CMD without uninstalling the (x86) version, but I’m not entirely sure how.

Hope it helps

Hey guys.

I have solved this problem only partially.

I mostly did what nachtrag mention in its post. I have just uninstalled other versions of the .net sdk and installed only the one recomended by godot webpage.
And this works but only in a way. Godot runs perfectly with this solution.

The problem comes that I use .NET for other applications and when I install any sdk from the Visual Studio Installer (the IDE I use) the .net version got overwritten in some way and Godot stops compiling and generating files.

I could go without installing the sdk for other applications, the problem comes that If I want to debug C# outside godot for godot projects, it needs to install .NET SDK from Visual Studio (at least if I use VS as my external IDE for Godot)

So I am not really sure how to set up all this without breaking it.

I think this is also the solution, but I have no idea how to change that either.

I have also tried to program without using an external IDE for for some errors, there is really slow and tedious debugging C# in Godot.

For now, and until Godot has a better support for C# development, I have paused any development I was working in godot.

Thank you very much to all of you for your answers and support. :slight_smile:

Hi,

I just wanted to add that my solution needs an addition because it caused two problems, which I realized to late. I installed Godot yesterday and tried to learn the basic functions, so I didn’t initially realize that this solution introduced two additional issues:

  1. You can’t export in Godot (basically, the export process freezes and does not progress because it is downloading the missing packages required to run .NET. I discovered this when I tried to publish via CMD).

  2. Visual Studio requests to download the 32-bit version again.
    And when you reinstall the 32-bit version, Godot stops working again.
    By deleting the 32-bit version of .NET, I also deleted the system environment variable for DOTNET_ROOT.

So basically, you need to manually set this variable again, and I think this is the missing step I didn’t know about yesterday.

To fix both issuse:

  1. Open CMD and type:
sysdm.cpl
  1. The System Properties window will open.

  2. Go to the “Advanced” tab and click “Environment Variables…”.

  3. Under “System variables”, look for DOTNET_ROOT.
    – If DOTNET_ROOT(x86) exists, delete it. (I think this is the incorrect path that causes the issues when reinstalling the 32-bit version)
    – If it doesn’t exist procced to the next step.

  4. Click on “new” to create a new system variable:
    Variable name: DOTNET_ROOT
    Variable value: C:\Program Files\dotnet
    – If your 64-bit .NET installation is in a different location, use that path instead.

  5. Restart your system and after restaring if your variable is set correct. Check this in cmd with:

echo %DOTNET_ROOT%

It should say something like that:

C:\Program Files\dotnet

You can also check under CMD

dotnet --info

At the enviromental variables it should say:

Environment variables:
  DOTNET_ROOT       [C:\Program Files\dotnet]

After this, you should be able to run Godot and install the 32-bit versions of .NET.

If this does not work, you might try publishing your application via CMD. I believe this will download the missing parts of .NET packages required for exporting in Godot. I did this while I was changing the system variable and before reinstalling the 32-bit versions.

So maybe this step is important.

I hope this helps. I just came up with this solution after a few hours of troubleshooting for myself…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.