aspnetboilerplate/aspnetboilerplate · error · ArgumentException
Given item is not type of
Error message
Given item is not type of
What it means
TypeList<TBaseType> only accepts types assignable to TBaseType. Its private CheckType method verifies item via typeof(TBaseType).IsAssignableFrom(item) and throws ArgumentException "Given item is not type of <TBaseType.AssemblyQualifiedName>" when the check fails. This keeps the typed list type-safe at runtime for dynamically supplied types.
Solutions
- Verify every type added inherits from or implements TBaseType
- Add a compile-time constraint (where T : TBaseType) or unit test over the scanned assembly
- Filter scanned types with typeof(TBaseType).IsAssignableFrom(t) before adding
- Catch ArgumentException and log the offending type instead of failing the whole registration
Example fix
// before
var types = Assembly.GetExecutingAssembly().GetTypes();
foreach (var t in types) typeList.Add(t);
// after
foreach (var t in Assembly.GetExecutingAssembly().GetTypes().Where(x => typeof(IMyHandler).IsAssignableFrom(x) && !x.IsAbstract))
typeList.Add(t); Defensive patterns
Strategy: type-guard
Validate before calling
if (!typeof(TBaseType).GetTypeInfo().IsAssignableFrom(itemType)) throw new ArgumentException($"{itemType} is not assignable to {typeof(TBaseType)}"); Type guard
bool IsCompatible(Type t) => typeof(TBaseType).GetTypeInfo().IsAssignableFrom(t);
Try / catch
try { typeList.Add(itemType); } catch (ArgumentException ex) when (ex.Message.StartsWith("Given item is not type of")) { /* log and skip type */ } Prevention
- Filter scanned assemblies with IsAssignableFrom before registration
- Add a unit test asserting all registered types satisfy the base constraint
- Re-run registration tests after refactoring base interfaces
When it happens
Trigger: Calling typeList.Add(someType) where someType does not inherit from/implement TBaseType — e.g. adding typeof(string) to a TypeList<IMyInterface>, or adding a derived class after the base contract changed.
Common situations: Plugin/convention-based registration scanning assemblies and adding wrong types; refactoring a class so it no longer implements the base interface while registration code still references it; assembly-loading picking up wrong version.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Can not find primary key type of given entity type: . Be…
- Cyclic dependency found! Item:
- Given job type does not implement IBackgroundJob<> or…
- unitOfWork is not type of…
- unitOfWork is not type of…
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/04fc61bfbb365ef3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp/Collections/TypeList.cs:150
_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 item is not type of " + typeof(TBaseType).AssemblyQualifiedName, "item");
}
}
}
}View on GitHub (pinned to 2323c13a15)