Repository: godot
Issue: C# EditorInspectorPlugin throws errors when connected to the Resource.Changed signal
Labels: bug,topic:dotnet

### Tested versions

Reproducible in: 4.2.stable.mono, 4.1.3.stable.mono, 4.1.stable.mono, 4.1.beta3.mono, 4.1.dev4.mono, 4.1.dev2.mono
Not-reproducible in: 4.0.4.stable.mono, 4.1.dev1.mono

### System information

Manjaro Linux

### Issue description

I'm trying to create an `EditorInspectorPlugin` in C# to display some information about a custom `Resource` I've created in the Inspector. The `EditorInspectorPlugin` connects to the `Changed` signal on the resource in order to redraw when the resource is changed. If any instance of the plugin is present in the Inspector when rebuilding the C# project, I get the following error message:

```
Attempt to disconnect a nonexistent connection from '<Resource#-9223369747536478755>'. Signal: 'changed', callable: 'Delegate::Invoke'.
```

Initially the plugin continues working, however rebuilding again gives the following errors mentioning #78513 and the plugin ceases functioning at all:

```
 /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:112 - System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'CustomResourceEditor'.
     at Godot.GodotObject.GetPtr(GodotObject instance) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 73
     at Godot.GodotObject.GetInstanceId() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/GodotObject.cs:line 461
     at Godot.DelegateUtils.TrySerializeSingleDelegate(Delegate delegate, Byte[]& buffer) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 151
     at Godot.DelegateUtils.TrySerializeDelegate(Delegate delegate, Array serializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 110
     at Godot.DelegateUtils.TrySerializeDelegateWithGCHandle(IntPtr delegateGCHandle, godot_array* nSerializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 302
  modules/mono/mono_gd/gd_mono.cpp:528 - .NET: Failed to unload assemblies. Please check https://github.com/godotengine/godot/issues/78513 for more information. (User)
  modules/mono/csharp_script.cpp:819 - Condition "managed_callable->delegate_handle.value == nullptr" is true. Continuing.
  /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:112 - System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'CustomResourceEditor'.
     at Godot.GodotObject.GetPtr(GodotObject instance) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 73
     at Godot.GodotObject.GetInstanceId() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/GodotObject.cs:line 461
     at Godot.DelegateUtils.TrySerializeSingleDelegate(Delegate delegate, Byte[]& buffer) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 151
     at Godot.DelegateUtils.TrySerializeDelegate(Delegate delegate, Array serializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 110
     at Godot.DelegateUtils.TrySerializeDelegateWithGCHandle(IntPtr delegateGCHandle, godot_array* nSerializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 302
  modules/mono/mono_gd/gd_mono.cpp:528 - .NET: Failed to unload assemblies. Please check https://github.com/godotengine/godot/issues/78513 for more information. (User)
  modules/mono/csharp_script.cpp:819 - Condition "managed_callable->delegate_handle.value == nullptr" is true. Continuing.
  /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/ExceptionUtils.cs:112 - System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'CustomResourceEditor'.
     at Godot.GodotObject.GetPtr(GodotObject instance) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:line 73
     at Godot.GodotObject.GetInstanceId() in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Generated/GodotObjects/GodotObject.cs:line 461
     at Godot.DelegateUtils.TrySerializeSingleDelegate(Delegate delegate, Byte[]& buffer) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 151
     at Godot.DelegateUtils.TrySerializeDelegate(Delegate delegate, Array serializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 110
     at Godot.DelegateUtils.TrySerializeDelegateWithGCHandle(IntPtr delegateGCHandle, godot_array* nSerializedData) in /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs:line 302
  modules/mono/mono_gd/gd_mono.cpp:528 - .NET: Failed to unload assemblies. Please check https://github.com/godotengine/godot/issues/78513 for more information. (User)
  modules/mono/mono_gd/gd_mono.cpp:512 - .NET: Giving up on assembly reloading. Please restart the editor if unloading was failing. (User)
```

This issue occurs when using the base `Resource` class as well, not only for the custom resource. Manually disconnecting the signal in either the destructor or `_ExitTree` method of the plugin does not help.

Maybe related to #76708?

### Steps to reproduce

* Open the MRP
* Build the project
* Double-click `test.tres` to open it in the Inspector.
* `MSBuild -> Rebuild Project`
* `MSBuild -> Rebuild Project` again

### Minimal reproduction project (MRP)

[TestProject.zip](https://github.com/godotengine/godot/files/13694115/TestProject.zip)