abpframework/abp · error · ArgumentException
Given type ({item.AssemblyQualifiedName}) should be instance
Error message
Given type ({item.AssemblyQualifiedName}) should be instance of {typeof(TBaseType).AssemblyQualifiedName} What it means
Thrown by TypeList<TBaseType>.CheckType when an item added to a strongly-typed TypeList is not assignable to the list's TBaseType constraint (checked via TypeInfo.IsAssignableFrom). It is an ArgumentException naming 'item' and reports both the offending and expected AssemblyQualifiedNames.
Source
Thrown at framework/src/Volo.Abp.Core/Volo/Abp/Collections/TypeList.cs:149
_typeList.CopyTo(array, arrayIndex);
}
/// <inheritdoc/>
public IEnumerator<Type> GetEnumerator()
{
return _typeList.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _typeList.GetEnumerator();
}
private static void CheckType(Type item)
{
if (!typeof(TBaseType).GetTypeInfo().IsAssignableFrom(item))
{
throw new ArgumentException($"Given type ({item.AssemblyQualifiedName}) should be instance of {typeof(TBaseType).AssemblyQualifiedName} ", nameof(item));
}
}
}
View on GitHub (pinned to 7ed43b1931)
Solutions
- Confirm item inherits or implements TBaseType; fix the type being registered.
- If TBaseType is too narrow for your need, widen the generic constraint on the list or use a plain List<Type>.
- Add a compile-time guard by filtering candidate types through typeof(TBaseType).IsAssignableFrom(t) before Add.
- Verify the plugin assembly matches the host framework version so the expected base type is present.
Example fix
// before
list.Add(typeof(SomeUnrelatedClass));
// after
if (typeof(TBaseType).IsAssignableFrom(typeof(SomeRelatedClass)))
{
list.Add(typeof(SomeRelatedClass));
} Defensive patterns
Strategy: type-guard
Validate before calling
static bool CanAdd<TBaseType>(Type t)
=> typeof(TBaseType).IsAssignableFrom(t);
if (CanAdd<IMyContract>(candidate)) list.Add(candidate); Type guard
static bool IsKindOf<TBase>(Type t) => typeof(TBase).IsAssignableFrom(t);
Try / catch
try
{
list.Add(candidate);
}
catch (ArgumentException ex) when (ex.ParamName == nameof(candidate))
{
logger.LogWarning("Rejected non-conforming type {Type}", candidate);
} Prevention
- Filter reflection-discovered types through IsAssignableFrom before adding to a TypeList.
- Keep the TBaseType constraint aligned with the actual interface your contributors implement.
- Add a unit test that registers each known contributor type against the list.
When it happens
Trigger: Calling Add/Insert on a TypeList<TBaseType> (or a class deriving from it, e.g. a module's ContributionTypes) with a Type that does not inherit/implement TBaseType.
Common situations: Registering a contributor type that is missing the required interface, a plugin assembly returning a type that no longer implements the expected base after a refactor, or a copy-paste of the wrong concrete class.
Related errors
- targetIndex should be between 0 and {source.Count - 1}
- {parameterName} is null!
- {parameterName} has a default value!
- Given type is not an ABP module: {moduleType.AssemblyQualifi
- Given module instance ({instance.GetType().AssemblyQualified
AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13).
Data as JSON: /api/errors/70e2a1631c2e92d6.
Report an issue: GitHub.