godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.31k stars 20k forks source link

"Unable to load .NET runtime, specifically hostfxr" due to Godot not seeing manually installed .NET SDK #75668

Open carlos-montes-karasu opened 1 year ago

carlos-montes-karasu commented 1 year ago

Godot version

4.0.2

System information

macOS Ventura 13.3 - M1 CPU

Issue description

I just installed .Net SDK (tried with 7.0 and 6.0 and same result) After download Godot .NET I opened it and then an error dialog appear the title

"Failed to Load .Net runtime" and the body "Unable to load .NET runtime, specifically hostfxr"

I do not know what else I can do, I can access dotnet command from my terminal, so I guess it was installed right

Steps to reproduce

Minimal reproduction project

N/A

Calinou commented 1 year ago

See the solution pointed out in https://github.com/godotengine/godot/issues/73747#issuecomment-1451292178.

tkepus commented 1 year ago

I have the exact same problem, except on the PC. Installed the latest SDK that matches my architecture (x64) and Godot still gives me the 'missing runtime' error.

I'm able to run .net applications, run dotnet, create a .net application, etc., but godot still fails to load the .net runtime...

faijeya commented 1 year ago

Reproduced and maybe solved on Steam Deck. tl;dr: export PATH=$PATH:~/.dotnet && export DOTNET_ROOT=~/.dotnet && ./Godot_v4.0.2-stable_mono_linux.x86_64

Steam Deck by default offers you an immutable system with everything of note installed via flatpaks or left in ~/ Official Microsoft .NET installer indeed left all it installed at ~/.dotnet Being immutable, whatever env variables did the .NET installer set up is lost as tears in rain.

Now, "Unable to load .NET runtime, specifically hostfxr" is fixed by setting DOTNET_ROOT Godot explicitly looks for (https://github.com/godotengine/godot/blob/3683b040eda27f33fece7a34fd1332572625c672/modules/mono/editor/hostfxr_resolver.cpp#L298) For me it's export DOTNET_ROOT=~/.dotnet

Then the editor will start, but will emit helpful errors like _"ERROR: .NET Sdk not found. The required version is '6.0.15'. at: godotsharp_pusherror (modules/mono/glue/runtimeinterop.cpp:1303)" After a bit of playing around it became clear that the source of it is in FindDotNetExe() (https://github.com/godotengine/godot/blob/0a0843a67d51eaacf5d3350d6c39a3893e3c1d6c/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs#L15)

For MacOS it seems like it looks in a couple of hardcoded locations, so nothing you can do except maybe symlink /usr/local/share/dotnet/ to wherever your dotnet executable is located. Dotnet executable should likely be named dotnet and respond with non-gibberish when launched as ./dotnet --list-sdks For other OS it looks for dotnet in PATH: takes every directory in PATH and looks in it. So I just do export PATH=$PATH:~/.dotnet

Now I'm unsure whether it solves-solves the problem as I just started setting up Godot and all sample mono projects are for 3.x, upgrade to 4.x without question and then fail to run in a sea of red ink, but that's likely normal.

richtaur commented 1 year ago

I was getting this error too (OS X 12.3). Here's what worked for me:

  1. Go here: https://dotnet.microsoft.com/en-us/download/dotnet/6.0
  2. Download SDK 6.0.408 (for me it was macOS / Arm64)
  3. Install
  4. Restart
  5. Godot no longer complains when it opens
shinspiegel commented 1 year ago

Reproduced and maybe solved on Steam Deck. tl;dr: export PATH=$PATH:~/.dotnet && export DOTNET_ROOT=~/.dotnet && ./Godot_v4.0.2-stable_mono_linux.x86_64

Now, "Unable to load .NET runtime, specifically hostfxr" is fixed by setting DOTNET_ROOT Godot explicitly looks for ( https://github.com/godotengine/godot/blob/3683b040eda27f33fece7a34fd1332572625c672/modules/mono/editor/hostfxr_resolver.cpp#L298

)

My DOTNET_ROOT looks correct, but still fails. Could you kindly elaborate more on the issue with the macOS? On the macOS it does not make the lookup for this env variable @faijeya?

shinspiegel commented 1 year ago

I'm not sure if this is correct, but I added a new entry for the lookout on the DotNotFinder class. Maybe this could be the solution to this issue.

This is the PR, https://github.com/godotengine/godot/pull/78994

shinspiegel commented 1 year ago

TLDR: ln -s /opt/homebrew/opt/dotnet/libexec /usr/local/share/dotnet


For now what I've done to solve the issue on macOS with the dotnet installed from the brew,

Need to create the symbolic link for the libexec path, and not for the dotnet itself. In this case I had to use the already created symlink from the brew located on /opt/homebrew/opt/dotnet.

But it requres the libexec folder, so small adjustment. The final symlink can be seen on the TLDR.

faijeya commented 1 year ago

@shinspiegel

elaborate more on the issue with the macOS?

Sure.

I'm completely unfamiliar with MacOS, but the code for MacOS there in DotNetFinder.cs checks for:

That's pretty much it, a single valid location per arch.

I'd propose to just collapse FindDotNetExe() to be just return OS.PathWhich("dotnet"); and add a MacOS-specific derivative of OS.WhichPath(). Least surprise and all that.

raulsntos commented 1 year ago

I'm also not very familiar with MacOS, but as far as I know the issue is that MacOS bundles aren't allowed to read user's environment variables which means we won't be able to read PATH or DOTNET_ROOT.

This means MacOS will only be able to find .NET if it's installed in the standard location (i.e.: using the installer from https://get.dot.net). It seems that homebrew doesn't install .NET to the standard location[^1], so creating a symbolic link would be the only way to solve this.

We also look for a file in /etc/dotnet/install_location (and /etc/dotnet/install_location_x64 for 64-bit OS), but I'm not sure if MacOS allows us to read this file. If it does, that would be another way to solve it. The file should contain a single line with the path to the .NET root directory (same as the DOTNET_ROOT environment variable).

By the way, how to search for .NET is documented in https://github.com/dotnet/designs/blob/main/accepted/2020/install-locations.md#host-behavior-for-30. We also look for .NET in PATH, but that's just added as a fallback in case the standard method fails.

[^1]: There's a PR that adds the hombrew install location to the search: https://github.com/godotengine/godot/pull/74221.

shinspiegel commented 1 year ago

This means MacOS will only be able to find .NET if it's installed in the standard location (i.e.: using the installer from https://get.dot.net). It seems that homebrew doesn't install .NET to the standard location1, so creating a symbolic link would be the only way to solve this.

The issue with this is,
The Microsoft installer is a hard installer, they access and modify things outside the userland, The same can be done with brew, which does not make things outside userland.

Maybe we could add a footnote on the docs to warn macOS users regarding the usage of brew and creating the symlink.

What do you folks thing about it?

JohnDorsey commented 11 months ago

Reproduced and maybe solved on Steam Deck. tl;dr: export PATH=$PATH:~/.dotnet && export DOTNET_ROOT=~/.dotnet && ./Godot_v4.0.2-stable_mono_linux.x86_64

I'm trying to launch Godot 4.1.1 mono on ubuntu 20.04. This gets me closer to success, but it still fails to load. This same installation of dotnet does not cause any errors when Godot 3.5.1 mono is launched.

$ export PATH=$PATH:~/.dotnet && export DOTNET_ROOT=~/.dotnet && ~/Desktop/Godot_v4.1.1-stable_mono_linux.x86_64 Godot Engine v4.1.1.stable.mono.official.bd6af8e0e - https://godotengine.org /lib/x86_64-linux-gnu/libxkbcommon.so.0: undefined symbol: xkb_utf32_to_keysym /lib/x86_64-linux-gnu/libxkbcommon.so.0: undefined symbol: xkb_keymap_key_get_mods_for_level OpenGL API 3.3.0 NVIDIA 470.161.03 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce GTX 1060 with Max-Q Design

Failed to load /home/john/.dotnet/shared/Microsoft.NETCore.App/6.0.11/libhostpolicy.so, error: /home/john/.dotnet/shared/Microsoft.NETCore.App/6.0.11/libhostpolicy.so: file too short An error occurred while loading required library libhostpolicy.so from [/home/john/.dotnet/shared/Microsoft.NETCore.App/6.0.11] Failed to initialize context for config: /home/john/BinInstalls/game_engines/godot/Godot_v4.1.1-stable_mono_linux_x86_64/GodotSharp/Api/Debug/GodotPlugins.runtimeconfig.json. Error code: 0x80008082 ERROR: hostfxr_initialize_for_runtime_config failed with code: -2147450750 at: initialize_hostfxr_for_config (modules/mono/mono_gd/gd_mono.cpp:200)

Does successfully launching godot 3.5.1 mono prove that my dotnet installation isn't broken?

UltimaTerra commented 8 months ago

I have a similar issue, same error as above, but I do have .NET via snap. Here is my environment variable. export DOTNET_ROOT=/snap/dotnet-sdk/228/sdk/8.0.100

I just checked my profile rc, and this issue is kind of weird. I just caved and am going to work with vanilla godot with gdscript and hope I can add gdextension with a language I am more comfortable (I don't need C# much, just wanted to report this issue as well.) This is on Pop OS.

jefetienne commented 6 months ago

We also look for a file in /etc/dotnet/install_location (and /etc/dotnet/install_location_x64 for 64-bit OS),

I managed to fix running Godot 4.2.1 .NET edition on my Steam Deck (after a manual binary download of .NET 6 to $HOME/.dotnet) by creating a symlink from /etc/dotnet/install_location to $HOME/.donet:

sudo mkdir -p /etc/dotnet
sudo ln -sT ~/.dotnet /etc/dotnet/install_location

My .bashrc contains these two lines:

export DOTNET_ROOT="$HOME/.dotnet"
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

/etc/ I believe persists its contents across OS updates. I think these steps should be the same solution for other immutable distros :)

EDIT: Not as easily fixed as I thought. I have to open a terminal into the Godot install folder, then manually ./Godot_v4.2.1-stable_mono_linux.x86_64 for it to find the runtime. Opening the executable directly through Dolphin or by a .desktop opens with the same "Unable to load .NET runtime" error for some reason. There might be an easy fix for this and I'm blanking on it.

alexkotusenko commented 3 months ago

I had the same issue on Mac M1. I downloaded .NET from the Microsoft website and set it up in my $PATH. It didn't work and it turned out that I downloaded the wrong macOS version (Intel instead of Silicon). I was able to open Godot with no errors once I downloaded the correct one and set it up in my PATH.

Btw, the dotnet executable is found directly in the /dotnet folder for silicon and in the /dotnet/x64 folder for intel.

I hope this helps someone