Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Port a DataContractSerialization bug fix from netfx #32205

Merged
merged 9 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ internal void EnsureSetAsIsReference(object obj)
{
if (_isReferenceArray == null)
{
_isReferenceArray = new bool[InitialArraySize];
_isReferenceArray = new bool[_objectArray.Length];
}
else if (_count == _isReferenceArray.Length)
else if (_count >= _isReferenceArray.Length)
{
Array.Resize<bool>(ref _isReferenceArray, _isReferenceArray.Length * 2);
Array.Resize<bool>(ref _isReferenceArray, _objectArray.Length);
}
_isReferenceArray[_count - 1] = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,22 @@ public static void DCS_TypeWithPrimitiveKnownTypes()
Assert.NotNull(actual);
}

[ActiveIssue(33317, TestPlatforms.OSX)]
[Fact]
public static void DCS_DeeplyLinkedData()
{
TypeWithLinkedProperty head = new TypeWithLinkedProperty();
TypeWithLinkedProperty cur = head;
for (int i = 0; i < 513; i++)
{
cur.Child = new TypeWithLinkedProperty();
cur = cur.Child;
}
cur.Children = new List<TypeWithLinkedProperty> { new TypeWithLinkedProperty() };
TypeWithLinkedProperty actual = DataContractSerializerHelper.SerializeAndDeserialize(head, baseline: null, skipStringCompare: true);
Assert.NotNull(actual);
}

private static T DeserializeString<T>(string stringToDeserialize, bool shouldReportDeserializationExceptions = true, DataContractSerializerSettings settings = null, Func<DataContractSerializer> serializerFactory = null)
{
DataContractSerializer dcs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,15 @@ public int IntValue
}
}

[DataContract(IsReference = true)]
public class TypeWithLinkedProperty
{
[DataMember]
public TypeWithLinkedProperty Child { get; set; }
[DataMember]
public List<TypeWithLinkedProperty> Children { get; set; }
}

[Serializable()]
[System.Xml.Serialization.XmlType("MsgDocumentType", Namespace = "http://example.com")]
[System.Xml.Serialization.XmlRoot("Document", Namespace = "http://example.com")]
Expand Down