can_instantiate: Cannot instantiate C# script because the associated class could not be found.

Godot Version

Godot v4.4.1.stable.mono

Question

So, I had this odd error that kept saying:

Script inherits from native type ‘CharacterBody2D’, so it can’t be assigned to an object of type: ‘Node’

… which made no sense to me because that was simply not the case.

So eventually I just deleted the script and the scene, but then I get this error:

E 0:00:01:026   can_instantiate: Cannot instantiate C# script because the associated class could not be found. Script: 'res://Scenes/game.tscn::CSharpScript_wowpa'. 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).
  <C++ Error>   Method/function failed. Returning: false
  <C++ Source>  modules/mono/csharp_script.cpp:2340 @ can_instantiate()

I am also getting this:

— Debugging process stopped —
ERROR: /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:113 - System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. : ‘C:\Users\fredr\OneDrive\Documents\papergame\Scenes\game.tscn::CSharpScript_wowpa’.

This persist when closing/opening Godot.

If I open the game.tscn file with a text editor, I can actually find this:

public partial class Spinner
{

}
"

This is the class I removed. I dont know or understand why this is even here? No other class seems to exist in this file. But then again, I dont know the structure of this file. And I really dont understand what that “ character is doing at the end?

If I delete the above from the file I will get this error instead:

ERROR: scene/resources/resource_format_text.cpp:39 - res://Scenes/game.tscn:211 - Parse Error: Unterminated string.

If I try removing larger parts of this file I get errors and/or it will simply not run (no errors, but nothing happens). Again, I dont know the structure of this file.

Anyway, it would be nice if this… was not an issue? Do I have to re-create my entire project now or what?

I’d simply check your git history to see where things broke and revert changed to that. This sounds like a disk corruption issue, or something on your PC causing problems with the project files.

You can try and delete the hidden “.godot” folder and then open the project again so Godot can re-import files.

I deleted everything in the game.tscn file that had “CSharpScript_wowpa“ in it, and the class Spinner.

This seems to have resolved it. No errors.