Unable to cast object of type 'DamageEffect' to type 'Effect\1[IEffectTarget]'.`

Godot Version

4.2, 4.3 dev 5

Question

Hello. I’m getting following error when I’m trying to compile my game:

Godot c# E 0:00:00:0430 object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object): System.InvalidCastException: Unable to cast object of type 'DamageEffect' to type 'Effect\1[IEffectTarget]'.`
<C++ Error> System.InvalidCastException
<C++ Source> :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
<Stack Trace> :0 @ object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object)
VariantUtils.generic.cs:385 @ T Godot.NativeInterop.VariantUtils.ConvertTo<T>(Godot.NativeInterop.godot_variant&)
Array.cs:1409 @ T Godot.Collections.Array\1.get_Item(int)`
Array.cs:1825 @ bool Godot.Collections.Array\1+<GetEnumerator>d__50.MoveNext()`
Card.cs:13 @ void Card.Play(IEffectTarget)
Main.cs:17 @ void Main._Ready()
Node.cs:2117 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
Main_ScriptMethods.generated.cs:38 @ bool Main.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)

This is my code (simplified version of it):

public interface IEffectTarget {}
public interface IDamageableEffectTarget : IEffectTarget {
    int Health { get; }
    void DealDamage (int number);
}
using Godot;

public abstract partial class Effect<T> : Resource where T : IEffectTarget
{
    [Export]
    public string DisplayName { get; private set; }

    [Export]
    public string Description { get; private set; }

    public abstract void Resolve(T target);
}
using Godot;

[GlobalClass]
public partial class DamageEffect : Effect<IDamageableEffectTarget>
{
    [Export]
    public int BaseDamage { get; private set; }

    public override void Resolve(IDamageableEffectTarget target)
    {
        target.DealDamage(BaseDamage);
    }
}
using Godot;

public partial class Enemy1 : Node3D, IDamageableEffectTarget
{
    [Export]
    public int Health { get; private set; } = 100;

    public void DealDamage(int number)
    {
        Health -= number;
    }
}
using Godot;

public partial class Main : Node {

    [Export]
    public Enemy1 Enemy1 { get; private set; }

    [Export] public Godot.Collections.Array<Effect<IEffectTarget>> Effects { get; private set; } 

    public override void _Ready() {
        foreach (var effect in Effects) // <- THIS IS THE LINE THAT CAUSES ABOVE ERROR
        {
            effect.Resolve(Enemy1);
        }
    }
}

Seems Godot is unable to cast ‘DamageEffect’ to type ‘Effect`1[IEffectTarget]’ inside foreach loop. I guess it’s somehow related to the fact that Effects property is of type Godot.Collections.Array.

It’s worth to mention that I’m using DamageEffect as a Resource which then I pass to the Main Scene as an array.

I’ve checked and it seems that if I’m not using generic type in Effect abstract class, it works.
So question is do GODOT support generic types?

Any ideas how to solve that?