{"record":{"id":"04fc61bfbb365ef3","repo":"aspnetboilerplate/aspnetboilerplate","slug":"given-item-is-not-type-of","errorCode":null,"errorMessage":"Given item is not type of ","messagePattern":"Given item is not type of ","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Abp/Collections/TypeList.cs","lineNumber":150,"sourceCode":"            _typeList.CopyTo(array, arrayIndex);\n        }\n\n        /// <inheritdoc/>\n        public IEnumerator<Type> GetEnumerator()\n        {\n            return _typeList.GetEnumerator();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return _typeList.GetEnumerator();\n        }\n\n        private static void CheckType(Type item)\n        {\n            if (!typeof(TBaseType).GetTypeInfo().IsAssignableFrom(item))\n            {\n                throw new ArgumentException(\"Given item is not type of \" + typeof(TBaseType).AssemblyQualifiedName, \"item\");\n            }\n        }\n    }\n}","sourceCodeStart":132,"sourceCodeEnd":154,"githubUrl":"https://github.com/aspnetboilerplate/aspnetboilerplate/blob/2323c13a152aa0ebfb37af3830f687d7f5b53795/src/Abp/Collections/TypeList.cs#L132-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar types = Assembly.GetExecutingAssembly().GetTypes();\nforeach (var t in types) typeList.Add(t);\n// after\nforeach (var t in Assembly.GetExecutingAssembly().GetTypes().Where(x => typeof(IMyHandler).IsAssignableFrom(x) && !x.IsAbstract))\n    typeList.Add(t);","handlingStrategy":"type-guard","validationCode":"if (!typeof(TBaseType).GetTypeInfo().IsAssignableFrom(itemType)) throw new ArgumentException($\"{itemType} is not assignable to {typeof(TBaseType)}\");","typeGuard":"bool IsCompatible(Type t) => typeof(TBaseType).GetTypeInfo().IsAssignableFrom(t);","tryCatchPattern":"try { typeList.Add(itemType); } catch (ArgumentException ex) when (ex.Message.StartsWith(\"Given item is not type of\")) { /* log and skip type */ }","preventionTips":["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"],"tags":["type-mismatch","argument-exception","type-list"],"backgroundTag":"type-mismatch","analyzedSha":"2323c13a152aa0ebfb37af3830f687d7f5b53795","analyzedAt":"2026-09-08T08:00:50.638Z","contentChangedAt":"2026-09-08T08:00:50.638Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}