{"record":{"id":"15086c16705facf9","repo":"JamesNK/Newtonsoft.Json","slug":"0-is-not-a-generic-class-definition","errorCode":null,"errorMessage":"'{0}' is not a generic class definition.","messagePattern":"'(.+?)' is not a generic class definition\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs","lineNumber":378,"sourceCode":"            }\n\n            implementingType = null;\n            return false;\n        }\n\n        public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition)\n        {\n            return InheritsGenericDefinition(type, genericClassDefinition, out _);\n        }\n\n        public static bool InheritsGenericDefinition(Type type, Type genericClassDefinition, out Type? implementingType)\n        {\n            ValidationUtils.ArgumentNotNull(type, nameof(type));\n            ValidationUtils.ArgumentNotNull(genericClassDefinition, nameof(genericClassDefinition));\n\n            if (!genericClassDefinition.IsClass() || !genericClassDefinition.IsGenericTypeDefinition())\n            {\n                throw new ArgumentNullException(\"'{0}' is not a generic class definition.\".FormatWith(CultureInfo.InvariantCulture, genericClassDefinition));\n            }\n\n            return InheritsGenericDefinitionInternal(type, genericClassDefinition, out implementingType);\n        }\n\n        private static bool InheritsGenericDefinitionInternal(Type type, Type genericClassDefinition, out Type? implementingType)\n        {\n            Type? currentType = type;\n            do\n            {\n                if (currentType.IsGenericType() && genericClassDefinition == currentType.GetGenericTypeDefinition())\n                {\n                    implementingType = currentType;\n                    return true;\n                }\n\n                currentType = currentType.BaseType();\n            }","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs#L360-L396","documentation":"Thrown by ReflectionUtils.InheritsGenericDefinition when the supplied genericClassDefinition is not a class or not a generic type definition. The argument must be an open generic class such as typeof(List<>); a closed generic class (List<int>) or a non-class type is rejected.","triggerScenarios":"Passing a closed generic class (typeof(List<int>)), a non-generic class, or an interface as the genericClassDefinition argument.","commonSituations":"Custom contract code probing inheritance against a closed generic, type confusion between interface and class definitions, or refactoring that swapped an open definition for a closed one.","solutions":["Pass an open generic class definition (e.g. typeof(List<>), typeof(Dictionary<,>)).","Validate with genericClassDefinition.IsClass && genericClassDefinition.IsGenericTypeDefinition before calling."],"exampleFix":"// before\nbool inherits = ReflectionUtils.InheritsGenericDefinition(type, typeof(Collection<int>));\n\n// after\nbool inherits = ReflectionUtils.InheritsGenericDefinition(type, typeof(Collection<>));","handlingStrategy":"validation","validationCode":"if (!genericClassDefinition.IsClass || !genericClassDefinition.IsGenericTypeDefinition)\n    throw new ArgumentException(\"Pass an open generic class definition, e.g. typeof(List<>)\");","typeGuard":"static bool IsOpenGenericClass(Type t) => t.IsClass && t.IsGenericTypeDefinition;","tryCatchPattern":null,"preventionTips":["Always pass open generic classes (typeof(List<>), typeof(Collection<>)) to InheritsGenericDefinition.","Validate IsClass && IsGenericTypeDefinition before calling.","Distinguish interface probing (ImplementsGenericDefinition) from class probing (InheritsGenericDefinition)."],"tags":["reflection","generics","class","argument"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}