Repository: godot
Issue: Loading Nodes with C# scripts attached using Godot.File.GetVar(true) throws an error
Labels: bug,topic:dotnet

<!-- Please search existing issues for potential duplicates before filing yours:
https://github.com/godotengine/godot/issues?q=is%3Aissue
-->

**Godot version:**
v3.2.3.stable.mono.official

**OS/device including version:**
Ubuntu 18.04.5 LTS

**Issue description:**
When using `Godot.File.StoreVar(node, true)` and `Godot.File.GetVar(true)` to save and load a Node with a C# script attached, an error is logged with the description of `can_instance: Cannot instance script because the class '' could not be found. Script: ''.` and the node is not recognized as belonging to the class it was saved as.

When using `Godot.File.StoreVar(node, true)` and `Godot.File.GetVar(true)` to save and load a Node with either no script attached or a GDScript attached, the node does not produce any errors.

See bottom of the report for further details.

Questionably similar issues I found while searching:
* https://github.com/godotengine/godot/issues/36828
* https://github.com/godotengine/godot/issues/40805

**Steps to reproduce:**
1. Create a new scene `CSharpScriptScene`.
2. Add a Node to `CSharpScriptScene` and attach a C# script to the node. No additional code in the file is necessary.
3. Create another scene, `SaveLoadScene`.
4. In the `_Ready()` function of `SaveLoadScene`, add code to save and load an instance of the new node using `Godot.File.StoreVar(node, true)` and `Godot.File.GetVar(true)`. The code below will work, or you can see the attached project.
5. Run the `SaveLoadScene` and observe the Output text and Debugger output.

Code snippets:
```
  private string _scenePrefabPath = "res://CSharpScriptScene.tscn";
  private string _fileLocation = "user://temp.save";

  private Node2D Load() {
    Godot.File savefile = new Godot.File();
    if(!savefile.FileExists(_fileLocation)) { throw new NotImplementedException(); }

    savefile.Open(_fileLocation, Godot.File.ModeFlags.Read);
    var scene = savefile.GetVar(true);
    savefile.Close();

    return scene as Node2D;
  }

  private void Save(Node2D node) {
    Godot.File savefile = new Godot.File();
    if(savefile.FileExists(_fileLocation)) { throw new NotImplementedException(); }

    savefile.Open(_fileLocation, Godot.File.ModeFlags.Write);
    savefile.StoreVar(node, true);
    savefile.Close();
  }

  private void Delete() {
    var directory = new Directory();
    directory.Remove(_fileLocation);
  }

  public override void _Ready() {
    var scene = GD.Load<PackedScene>(_scenePrefabPath).Instance() as Node2D;
    Save(scene);
    var node = Load();
    GD.Print(string.Format("Returned node is {0}. Can cast to CSharpScriptScene: {1}", node, node is CSharpScriptScene));

    GD.Print("    Adding child node " + node);
    AddChild(node);
    RemoveChild(node);
    GD.Print("    Removing child node " + node);
    GD.Print("");

    Delete();
  }
```

**Minimal reproduction project:**
See https://github.com/MoyTW/GodotCannotInstanceCSharpScriptNodeExample or [CSharpSaveLoadError.zip](https://github.com/godotengine/godot/files/5405039/CSharpSaveLoadError.zip)

**Further Details**

Output from running the example project and clicking all the buttons. Illustrates save/load from a Node2D with no script, a Node2D with a C# script attached, and a Node2D with a GDScript script attached. Demonstrates that you can add/remove the nodes with no issues, and that the GDScript `_ready()` function is invoked but the C# `_Ready()` function is not.
```
--- Debugging process started ---
Godot Engine v3.2.3.stable.mono.official - https://godotengine.org
OpenGL ES 2.0 Renderer: Mesa DRI Intel(R) UHD Graphics 620 (KBL GT2)
OpenGL ES 2.0 Batching: ON
 
Returned node from NO SCRIPT is [Node2D:1441]. Can cast to CSharpScriptScene: False
    Adding child node [Node2D:1441]
    Removing child node [Node2D:1441]

Returned node from C# SCRIPT is [Node2D:1491]. Can cast to CSharpScriptScene: False
    Adding child node [Node2D:1491]
    Removing child node [Node2D:1491]

Returned node from GDSCRIPT is [Node2D:1577]. Can cast to CSharpScriptScene: False
    Adding child node [Node2D:1577]
        GDScript scene ready!
    Removing child node [Node2D:1577]

--- Debugging process stopped ---
```

Full error from Debugger:
```
E 0:00:02.527   can_instance: Cannot instance script because the class '' could not be found. Script: ''.
  <C++ Error>   Method failed. Returning: __null
  <C++ Source>  modules/mono/csharp_script.cpp:2942 @ can_instance()
  <Stack Trace> :0 @ System.Object Godot.NativeCalls.godot_icall_1_608(IntPtr , IntPtr , Boolean )()
                File.cs:460 @ System.Object Godot.File.GetVar(Boolean )()
                SaveLoadButton.cs:18 @ Godot.Node2D SaveLoadButton.Load()()
                SaveLoadButton.cs:41 @ void SaveLoadButton.OnSaveLoadButtonPressed()()
```