Repository: godot
Issue: [C#] Wrong type returned by ResourceLoader.Load when attempting to load a custom resource type in the editor context
Labels: discussion,topic:dotnet

### Godot version

4.2.dev3

### System information

Windows 10 - Godot v4.2.dev3 - Vulkan (Forward+)

### Issue description

When attempting to load a resource using a custom implemented type, `ResourceLoader.Load<>` returns the wrong type **only when called in the editor context**.

**Expected behavior**

`ResourceLoader.Load<>` should return an object of the custom type.
In the reproduction project, it should return an object of the type `MyCustomResource`, and print out the following lines to the ouput:

```
It works!
blah
123
1.2
```

**Current behavior**

`ResourceLoader.Load<>` returns the default type `Resource`, causing an invalid cast exception when calling the function with a custom type.
In the reproduction project, this is the current output:

```
  /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:112 - System.InvalidCastException: Unable to cast object of type 'Godot.Resource' to type 'MyCustomResource'.
     at Godot.ResourceLoader.Load[T](String path, String typeHint, CacheMode cacheMode) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/ResourceLoaderExtensions.cs:line 27
     at MyCustomResourceLoader._Ready() in H:\Workspace\CustomResourceLoadingIssue\scripts\MyCustomResourceLoader.cs:line 11
     at Godot.Node.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/Node.cs:line 2101
     at MyCustomResourceLoader.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) in H:\Workspace\CustomResourceLoadingIssue\Godot.SourceGenerators\Godot.SourceGenerators.ScriptMethodsGenerator\MyCustomResourceLoader_ScriptMethods.generated.cs:line 38
     at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** args, Int32 argCount, godot_variant_call_error* refCallError, godot_variant* ret) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/CSharpInstanceBridge.cs:line 24
```

**Additional note**

Everything works as expected when running the project. This issue only happens when the same code is running in the editor context / a script has the `[Tool]` attribute.

### Steps to reproduce

1. Create a custom resource type inheriting from `Resource` and with the `[GlobalClass]` attribute.
2. Compile the C# project, then go to the editor, and create a new resource of the newly implemented type. Copy the path to that file.
3. Create a C# script with the `[Tool]` attribute.
4. Override the `_Ready` method, and add a call to `ResourceLoader.Load<CustomType>("res://path/to/that/resource")`.

### Minimal reproduction project

[CustomResourceLoadingIssue.zip](https://github.com/godotengine/godot/files/12441911/CustomResourceLoadingIssue.zip)

To reproduce the issue, **you must close the main scene tab, then compile the C# project, then open the main scene again.**