Fixed serializing abstract base class ISerializable on .NET Core (#1712)

This commit is contained in:
James Newton-King
2018-05-21 11:17:19 +12:00
committed by GitHub
parent aa4062d586
commit 32f882b5d6
3 changed files with 114 additions and 4 deletions
@@ -1706,6 +1706,11 @@ namespace Newtonsoft.Json.Serialization
ThrowUnexpectedEndException(reader, contract, serializationInfo, "Unexpected end when deserializing object.");
}
if (!contract.IsInstantiable)
{
throw JsonSerializationException.Create(reader, "Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
}
if (contract.ISerializableCreator == null)
{
throw JsonSerializationException.Create(reader, "ISerializable type '{0}' does not have a valid constructor. To correctly implement ISerializable a constructor that takes SerializationInfo and StreamingContext parameters should be present.".FormatWith(CultureInfo.InvariantCulture, objectType));