godot: can_instantiate: Cannot instance script because the associated class could not be found. Script: 'res://testClass.cs'. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly (it's case-sensitive).

Godot version

4.0 Beta 13 Mono

System information

Windows 10 Pro 22H2

Issue description

This issue proves that #66419 is still not fixed

I’m using Godot 4 Beta Mono and for some reason some projects glitch and keep showing me this error (title of the issue). I’ve decided to make a test project to reproduce it and couldn’t find a way to do it, so i just duplicated a project i had and wiped all the files in it in order to create a single scene with a single script called testClass.cs, and this way i could reproduce it but what causes it to happen is unknown to me. Here’s the content of the script:

using Godot;
using System;

public partial class testClass : Node2D
{
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}
}

the class name matches the file name and the script is in the right path, it even opens on VSCode (which i’m using for the project as the main editor). I’ve also noticed after messing with other non glitched projects that the ones that are glitched do not allow me to open any file in the OS file system by right clicking and selecting the option:

image

Whenever i click this option on a glitched project it just does nothing, while in other projects (in the same version of Godot and using C# and VSCode as well) it just normally opens the OS file system and shows the project as expected.

Changing the project to another folder, erasing the .godot folder and trying to re-open in the editor and reload the files do not solve it, once a project get this glitch it’ll be it, at least in my experiences and tests. Even deleting the entire project and recloning it (in case it’s a project on github) does not solve the problem.

Tried it in a 3.x version and couldn’t replicate the bug.

Steps to reproduce

Just create a project, a main node and a C# script in Godot 4.0 Beta 13 Mono (i had the same issue in Beta 9 forward so any of those might have that too) and see if it happens, the exact steps are unclear since i tried adding more scenes, scripts, folders and everything to another test project and it didn’t happened. Luckly i have a minimal reproduction project that have this problem, be aware that this problem might not happen on Linux or any Windows version besides 10.

Minimal reproduction project

Just open it an run with F5

Minimum reproduction project.zip

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

I had this error in beta14 and just fixed it. For me, it was caused by my godot project’s “dotnet/project/assembly_name” setting no longer matching the assembly name of the Visual Studio solution/project.

And I think the mismatch happened because the dotnet project’s assembly name defaults to $(MSBuildProjectName) and I had adjusted the project name.

image

Further conjecture: Godot may keep working after you change a c# project name because it’s linking to old assemblies, and the “associated class could not be found” error doesn’t start occurring until you do a clean. A symptom that something was amiss for me was that Godot was no longer spending any time in the “Building .NET Project” progress dialog whenever I clicked run.

I got this error when making a new project and copying script files into it and trying to use them. I fixed it with Project->Tools->C#->Create C# solution

I think I found the cause of this issue. I was missing this tag in my .csproj file. Once I added it, the can_instantiate error went away,

<EnableDynamicLoading>true</EnableDynamicLoading>

Still having other showstopping bugs, so back to 3.5 for now

just some more info!

I’ve tried on linux, it ran fine without any problem, but when clicking Open in file manager this message appeared:

kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found

this is specific to Manjaro KDE file manager, so probably there’s a problem in godot interaction with system’s file manager, keep in mind that in linux even with this error message, it still shows the project folder!

@Treer I’ve checked it and apparently there’s no mismatch here, Both have the same name in VS Code and Godot and i never changed the project’s name. but your answer might be usefull for a lot of people 😄