-Improve error message when attempting to deserialize to an interface or abstract class

This commit is contained in:
JamesNK
2009-02-08 08:57:45 +00:00
parent 50cca1ec0b
commit eedb01645a
2 changed files with 39 additions and 1 deletions
+5 -1
View File
@@ -493,7 +493,11 @@ namespace Newtonsoft.Json
{
object newObject;
if (ReflectionUtils.HasDefaultConstructor(objectType))
if (objectType.IsInterface || objectType.IsAbstract)
{
throw new JsonSerializationException("Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantated.".FormatWith(CultureInfo.InvariantCulture, objectType));
}
else if (ReflectionUtils.HasDefaultConstructor(objectType))
{
newObject = Activator.CreateInstance(objectType);