{"record":{"id":"d88bf8bada4b3d2f","repo":"JamesNK/Newtonsoft.Json","slug":"target-type-0-is-not-a-value-type-or-a-non-abstr","errorCode":null,"errorMessage":"Target type {0} is not a value type or a non-abstract class.","messagePattern":"Target type (.+?) is not a value type or a non-abstract class\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ConvertUtils.cs","lineNumber":391,"sourceCode":"        {\n            Success = 0,\n            CannotConvertNull = 1,\n            NotInstantiableType = 2,\n            NoValidConversion = 3\n        }\n\n        [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        public static object Convert(object initialValue, CultureInfo culture, Type targetType)\n        {\n            switch (TryConvertInternal(initialValue, culture, targetType, out object? value))\n            {\n                case ConvertResult.Success:\n                    return value!;\n                case ConvertResult.CannotConvertNull:\n                    throw new Exception(\"Can not convert null {0} into non-nullable {1}.\".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType));\n                case ConvertResult.NotInstantiableType:\n                    throw new ArgumentException(\"Target type {0} is not a value type or a non-abstract class.\".FormatWith(CultureInfo.InvariantCulture, targetType), nameof(targetType));\n                case ConvertResult.NoValidConversion:\n                    throw new InvalidOperationException(\"Can not convert from {0} to {1}.\".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType));\n                default:\n                    throw new InvalidOperationException(\"Unexpected conversion result.\");\n            }\n        }\n\n        [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]\n        [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]\n        private static bool TryConvert(object? initialValue, CultureInfo culture, Type targetType, out object? value)\n        {\n            try\n            {\n                if (TryConvertInternal(initialValue, culture, targetType, out value) == ConvertResult.Success)\n                {\n                    return true;\n                }\n","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs#L373-L409","documentation":"ConvertUtils.Convert throws this (as ArgumentException) when TryConvertInternal returns ConvertResult.NotInstantiableType (ConvertUtils.cs:390-391). That happens when the target type is an interface, an open generic type definition, or an abstract class (ConvertUtils.cs:581-585) — none of which can be instantiated or meaningfully converted into.","triggerScenarios":"Calling ConvertUtils.Convert (directly or via the deserialization pipeline) with targetType equal to an interface (IEnumerable, IList), an open generic (typeof(List<>)), or an abstract base class.","commonSituations":"Reflection/generic code that loses the concrete type and passes an interface or open generic as the target; misconfigured contracts that resolve a property to an abstract type; dynamic typing losing closure.","solutions":["Pass a concrete, closed type (List<object>, a concrete subclass) as the target.","Resolve the concrete runtime type before conversion (e.g. via a factory or type mapping).","If the source is JSON, configure JsonSerializerSettings/ContractResolver to pick a concrete type for the property.","Validate targetType with !targetType.IsAbstract && !targetType.IsInterface && !targetType.IsGenericTypeDefinition before calling Convert."],"exampleFix":"// before\nobject o = ConvertUtils.Convert(value, culture, typeof(IEnumerable));\n// after\nobject o = ConvertUtils.Convert(value, culture, typeof(List<object>));","handlingStrategy":"validation","validationCode":"// Reject interfaces/open-generics/abstract types before calling Convert.\nstatic void EnsureInstantiable(Type t) {\n    if (t.IsInterface || t.IsAbstract || t.IsGenericTypeDefinition)\n        throw new ArgumentException($\"Target type {t} must be a concrete, closed type.\");\n}","typeGuard":"static bool IsInstantiable(Type t) => !t.IsInterface && !t.IsAbstract && !t.IsGenericTypeDefinition;","tryCatchPattern":"try { return ConvertUtils.Convert(value, culture, targetType); } catch (ArgumentException ex) when (ex.Message.Contains(\"not a value type or a non-abstract class\")) { /* resolve a concrete subtype */ }","preventionTips":["Always pass a concrete, closed type as the conversion target.","Validate targetType with IsInstantiable before converting.","Resolve abstract/interface properties to a concrete type via a contract resolver."],"tags":["conversion","reflection","type-mismatch","newtonsoft-json"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}