public class GenericArrayQueryHandler<T> : IQueryHandler<GenericArrayQuery<T>, Tuple<T>[]> { }
This type is generic, and it's generic type T goes into the generic type arguments of the implementing interface. One of the types, Tuple<T>[] is a 'generic array', as in, its element type is generic.
Simple Injector can't handle this specific case when, and only when, the type is registered as open generic.
The following type, on the other hand, doesn't exhibit the problem:
public class GenericArrayQueryHandler<T> : IQueryHandler<GenericArrayQuery<T>, List<Tuple<T>>> { }
Expected behavior
The type GenericArrayQueryHandler<int> is created and resolved by Simple Injector.
Actual behavior
The following exception is thrown:
System.InvalidOperationException: This operation is only valid on generic types.
Not only should an exception not be thrown, the exception is highly generic and confusing.
To Reproduce
The following code reproduces the issue:
var container = new Container();
container.Register(typeof(IQueryHandler<,>), typeof(GenericArrayQueryHandler<>));
container.GetInstance<IQueryHandler<GenericArrayQuery<int>, Tuple<int>[]>>();
public class GenericArrayQuery<T> : IQuery<Tuple<T>[]> { }
public class GenericArrayQueryHandler<T> : IQueryHandler<GenericArrayQuery<T>, Tuple<T>[]> { }
Describe the bug
Consider the following type:
This type is generic, and it's generic type
T
goes into the generic type arguments of the implementing interface. One of the types,Tuple<T>[]
is a 'generic array', as in, its element type is generic.Simple Injector can't handle this specific case when, and only when, the type is registered as open generic.
The following type, on the other hand, doesn't exhibit the problem:
Expected behavior
The type
GenericArrayQueryHandler<int>
is created and resolved by Simple Injector.Actual behavior
The following exception is thrown:
Not only should an exception not be thrown, the exception is highly generic and confusing.
To Reproduce
The following code reproduces the issue:
Additional context
Simple Injector v5.4.4.