Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when trying to open C# project with .NET installed in non-standard location (but in PATH) #66353

Open
Zekiah-A opened this issue Sep 24, 2022 · 9 comments

Comments

@Zekiah-A
Copy link

Godot version

Godot Engine v4.0.beta1.mono.official (4ba934b)

System information

Arch Linux, Vulkan, GTX 1050

Issue description

When attempting to open a C# project on godot 4 beta mono I get the following error

Godot Engine v4.0.beta1.mono.official.4ba934bf3 - https://godotengine.org
Vulkan API 1.2.0 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1050
 
ERROR: The host fxr folder does not exist: /usr/share/dotnet/host/fxr
   at: try_get_path_from_dotnet_root (modules/mono/editor/hostfxr_resolver.cpp:323)
ERROR: .NET: One of the dependent libraries is missing. Typically when the `hostfxr`, `hostpolicy` or `coreclr` dynamic libraries are not present in the expected locations.
   at: find_hostfxr (modules/mono/mono_gd/gd_mono.cpp:126)
ERROR: .NET: Failed to load hostfxr
   at: initialize (modules/mono/mono_gd/gd_mono.cpp:397)
Project is missing: /home/zekiah/Downloads/godot-reflection/project.godot
Project is missing: /home/zekiah/Downloads/Liblast-main/liblast/Game/project.godot
Editing project: /home/zekiah/Documents/MandemTerritory
Godot Engine v4.0.beta1.mono.official.4ba934bf3 - https://godotengine.org
Vulkan API 1.2.0 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1050
 
ERROR: The host fxr folder does not exist: /usr/share/dotnet/host/fxr
   at: try_get_path_from_dotnet_root (modules/mono/editor/hostfxr_resolver.cpp:323)
ERROR: .NET: One of the dependent libraries is missing. Typically when the `hostfxr`, `hostpolicy` or `coreclr` dynamic libraries are not present in the expected locations.
   at: find_hostfxr (modules/mono/mono_gd/gd_mono.cpp:126)
ERROR: .NET: Failed to load hostfxr
   at: initialize (modules/mono/mono_gd/gd_mono.cpp:397)
WARNING: FBX file import is enabled in the project settings, but no FBX2glTF path is configured in the editor settings. FBX files will not be imported.
     at: _editor_init (modules/gltf/register_types.cpp:99)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.beta1.mono.official (4ba934bf3d1e697d8f332b5e8cfd694cdf49a7ba)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /usr/lib/libc.so.6(+0x38a00) [0x7f4122a92a00] (??:0)
-- END OF BACKTRACE --
================================================================

I do have dotnet installed, evident as when I run,

❯ dotnet --list-sdks
6.0.302 [/home/zekiah/dotnet/sdk]
7.0.100-preview.6.22352.1 [/home/zekiah/dotnet/sdk]
❯ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.7 [/home/zekiah/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-preview.6.22330.3 [/home/zekiah/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.7 [/home/zekiah/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.6.22324.4 [/home/zekiah/dotnet/shared/Microsoft.NETCore.App]

, you can see everything is installed as expected, when I run which dotnet, I get /home/zekiah/dotnet/dotnet, I suspect this may be an issue as godot is only seeming to look in ERROR: The host fxr folder does not exist: /usr/share/dotnet/host/fxr for dotnet. When searching within /home/zekiah/dotnet/dotnet, the host/fxr dir does exist there.

Steps to reproduce

  • Install dotnet via the install scripts, or some other method that does not result in the dotnet directory not being located in /usr/share/dotnet/

Minimal reproduction project

No response

@akien-mga akien-mga changed the title Godot 4 beta 1 crash when trying to open c# project Godot 4 beta 1 crash when trying to open c# project with dotnet installed in non standard location (but in PATH) Sep 24, 2022
@akien-mga akien-mga added this to the 4.0 milestone Sep 24, 2022
@raulsntos
Copy link
Member

Godot should also be looking at the location of the dotnet executable in PATH but I'm not seeing it in the error. Can you check if /home/zekiah/dotnet is in the PATH environment variable?

Also, do the /etc/dotnet/install_location or /etc/dotnet/install_location_x64 files exist for you?

You can also try setting the DOTNET_ROOT environment variable to /home/zekiah/dotnet and see if that fixes it for you as a workaround.

@Zekiah-A
Copy link
Author

Also, do the /etc/dotnet/install_location or /etc/dotnet/install_location_x64 files exist for you?
You can also try setting the DOTNET_ROOT environment variable to /home/zekiah/dotnet and see if that fixes it for you as a workaround.

Nor /etc/dotnet/install_location_x64, or /etc/dotnet/install_location seem to exist for me,

❯ /etc/dotnet/install_location
zsh: no such file or directory: /etc/dotnet/install_location
❯ /etc/dotnet/install_location_x64
zsh: no such file or directory: /etc/dotnet/install_location_x64

However, setting DOTNET_ROOT to the path of the dotnet excutable seems to at least allow me to run the editor and open a C# project, even if it still complains about The host fxr folder does not exist: /usr/share/dotnet/host/fxr

❯ DOTNET_ROOT=$(which dotnet) ./Godot_v4.0-beta1_mono_linux.x86_64
Godot Engine v4.0.beta1.mono.official.4ba934bf3 - https://godotengine.org
Vulkan API 1.2.0 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1050
 
ERROR: The host fxr folder does not exist: /usr/share/dotnet/host/fxr

@Anixias
Copy link

Anixias commented Feb 19, 2023

Similar problem on Windows 11, my fiancée has the game close instantly and running from command prompt yields ".NET: Failed to load hostfxr" as the only output. She does have .NET 7 installed in the standard location, and hostfxr.dll definitely exists in the right folder. I'm building the game with v4.0.rc2.mono.official [d2699dc].

@raulsntos
Copy link
Member

raulsntos commented Feb 20, 2023

@Anixias Would you be able to open the game from a terminal with the --verbose flag? It may contain more useful information to help us figure out what went wrong.

An exported game should contain the hostfxr.dll in the data folder, if you move the game binary make sure to move the data folder with it. Perhaps you run into #72159.

@Anixias
Copy link

Anixias commented Feb 20, 2023

I'll give it a shot when I can. That seems like it could be the issue I'm facing, although the same PCK works on my own computer.

@Anixias
Copy link

Anixias commented Feb 21, 2023

image

This is all it says. This is on another friend's PC running Windows 10.

EDIT: I didn't see your text about the data folder, thought it was a dump from the export process and didn't realize it needed to be included with the application.... I assumed all data was in the PCK file. So sorry!

@YuriSizov YuriSizov changed the title Godot 4 beta 1 crash when trying to open c# project with dotnet installed in non standard location (but in PATH) Crash when trying to open C# project with .NET installed in non-standard location (but in PATH) Feb 21, 2023
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 27, 2023
@Treer
Copy link
Contributor

Treer commented Mar 5, 2023

I've had this hostfxr problem (v4.0.stable.mono.official [92bee43]) and solved it, though I suspect it can have many different causes. In my case I could run the project from the editor, but if I exported the project and tried to run the exported .exe, I get

ERROR: .NET: Failed to load hostfxr
   at: (modules/mono/mono_gd/gd_mono.cpp:399)

It sounds like @Zekiah-A is having the problem in the editor (?), while @Anixias has the problem when launching an exported game (like me).

Godot 4.0 beta 16 introduced Initial .NET 7 support, and Anixias mentions "She does have .NET 7 installed". However, I see that initial .NET 7 support "does not change the target framework the godot assemblies, instead it just allows the godot editor to run using the latest .NET version installed on the machine (including .NET 7).". Perhaps the editor runs because it can run on .net 7, but the project doesn't build correctly because it targets .net 6 and .net 6 is not installed? I've not looked into this .net 7 support, so that is just a suggestion shooting from the hip and may not be the cause.

The cause of my Failed to load hostfxr is a silent issue with MSBuild that comes into play when I export. i.e. there's nothing wrong with the .net environment, rather it's the .exe that was exported that is bad.

There's two ways to know this is happening, firstly the "Publishing .NET project..." step is skipped during export - the export is suspiciously fast and this I don't see this progress-bar dialog (I do still see the other progress-bar dialog)
image

Secondly, the editor is missing the MSBuild panel, I see:
image
But in a working project it looks like this:
image

In my case, the trigger was that my .sln file didn't have the same file name as the Assembly Name in Project Settings→ General→ Dotnet→ Project (more on that later).

So I assume Godot couldn't find the .sln file, silently switched into some sort of "not a dotnet project" mode and so didn't do a complete build when exporting the project. I presume the reason the project was running fine in the editor is I had been developing the c# parts in a different IDE (vs2022) which meant the assemblies were already compiled and present somewhere that Godot was expecting.

So if an exported file quits with ERROR: .NET: Failed to load hostfxr, and the .net6 runtime is confirmed to be installed, check also whether Godot was building the .net part of it during export - I'm guessing there are more scenarios than mine which will trigger this.


In my specific case, the settings don't allow me to specify a .sln (only a solution directory, in my case the parent directory), and don't make it clear that the solution file must stay named the same as the Assembly Name (I thought keeping both the csproj name and the csproj's assembly name the same would have been sufficient), but the main issue is that you don't know when the dotnet settings have failed, weird errors just start to appear days later - I've had a similar but different issue caused by silent failure in the dotnet project settings here.

In in the meantime I can now keep an eye on whether the MSBuild panel exists

@yingshaoxo
Copy link

Try this:

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod 777 dotnet-install.sh 
./dotnet-install.sh --channel 7.0

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

Use microsoft script to install dotnet. It works fine.

@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 23, 2023
@kepiz
Copy link

kepiz commented Sep 15, 2023

Try this:

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod 777 dotnet-install.sh 
./dotnet-install.sh --channel 7.0

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

Use microsoft script to install dotnet. It works fine.

How do I point godot to the right folder?
I have installed with your commands but still have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

8 participants