godot
godot copied to clipboard
.NET: Failed to load project assembly, Cannot instance script because the associated class could not be found.
Godot version
4.0.beta6.mono.official
System information
Windows 11 , dotnet 6.0.402
Issue description
Moving ProjectName.sln
outside the project dir causes the engine to fail loading the project assembly .
The project i am working on contains multiple dotnet core projects alongside the Godot project and am trying to follow this folder structure :
MainFolder ├── ProjectName.sln ├── src │ ├── ProjectName (godot project ) │ │ ├── ProjectName.csproj │ │ ├── project.godot │ ├── ProjectName.AnotherDotnetProject │ │ ├── ProjectName.AnotherDotnetProject.csproj
in the godot project i have set the Settings > Dotnet > Project :
Assembly Name : ProjectName
Solution Directory : ../../
C# Project Directory : .
i have modified the .sln
file to point to the correct .csproj
.
There is NO ISSUE building the project with godot editor or dotnet build.
But when am running the project it fails to load all .cs
classes and the console prints .NET: Failed to load project assembly
with a list of .cs
files:
Example with --verbose enabled
TextServer: Primary interface set to: "ICU / HarfBuzz / Graphite (Built-in)".
.NET: Initializing module...
Found hostfxr: C:\Program Files\dotnet\host/fxr/7.0.0/hostfxr.dll
.NET: hostfxr initialized
.NET: GodotPlugins initialized
.NET: Failed to load project assembly
CORE API HASH: 2925030599
EDITOR API HASH: 2261696631
Loaded builtin certs
ERROR: Cannot instance script because the associated class could not be found. Script: 'res://Node2D.cs'.
at: (modules/mono/csharp_script.cpp:2288)
Steps to reproduce
- Create godot dotnet project.
- move
.sln
file outside main project folder - update
.sln
file to point to the correct.csproj
folder - update Solution Directory and C# Project Directory from the godot dotnet settings ,
- build success but running the project fails .
Minimal reproduction project
Maybe related to this 9c698629499a9a8fffb74a3ec4c2bfac6b7a1484 .
I think Godot is trying to find the assembly in the .godot
directory relative to the Godot project directory:
/src/DotnetSolutionDirectory/.godot/mono/temp/bin/Debug/DotnetSolutionDirectory.dll
But due to the Godot.NET.Sdk props, the output is likely relative to the .sln
file which means the assembly is built to:
/.godot/mono/temp/bin/Debug/DotnetSolutionDirectory.dll
https://github.com/godotengine/godot/blob/4a82d71d7345d0dde4da2816fd489da1c303f580/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props#L15-L17
https://github.com/godotengine/godot/blob/4a82d71d7345d0dde4da2816fd489da1c303f580/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props#L20-L21
Fixed by https://github.com/godotengine/godot/pull/69391
Note that the .csproj
location is no longer configurable and must always be next to the project.godot
file now, which it is in your case so you should be good.
Saw this error on 4.1.2
It was happening because I had an apostrophe in my project's name.