diff --git a/src/Argon/Serialization/JsonSerializerInternalReader.cs b/src/Argon/Serialization/JsonSerializerInternalReader.cs index 1a321b2b..28f84c9f 100644 --- a/src/Argon/Serialization/JsonSerializerInternalReader.cs +++ b/src/Argon/Serialization/JsonSerializerInternalReader.cs @@ -1961,6 +1961,11 @@ List ResolvePropertyAndCreatorValues(JsonObjectContract continue; } + + if (!reader.Read()) + { + throw JsonSerializationException.Create(reader, $"Unexpected end when setting {memberName}'s value."); + } } else { diff --git a/src/Tests/Issues/Issue2708.cs b/src/Tests/Issues/Issue2708.cs new file mode 100644 index 00000000..26dbfad9 --- /dev/null +++ b/src/Tests/Issues/Issue2708.cs @@ -0,0 +1,38 @@ +// Copyright (c) 2007 James Newton-King. All rights reserved. +// Use of this source code is governed by The MIT License, +// as found in the license.md file. + +public class Issue2708 : TestFixtureBase +{ + [Fact] + public void Test() + { + string json = @" +{ + ""Name"": ""MyName"", + ""ChildClassProp"": ""MyValue"", +}"; + + var record = JsonConvert.DeserializeObject(json); + Assert.Equal(null, record.Name); // Not set because doesn't have DataMember + Assert.Equal("MyValue", record.ChildClassProp); + } + + [DataContract] + public abstract class RecordBase + { + [JsonExtensionData] + protected IDictionary additionalData; + + public string Name { get; set; } + } + + [DataContract] + public class MyRecord : RecordBase + { + public MyRecord(string childClassProp) => ChildClassProp = childClassProp; + + [DataMember] + public string ChildClassProp { get; set; } + } +} \ No newline at end of file