Skip to content
Draft
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 @@ -392,7 +392,7 @@ internal static int GetIdForInitialization(ClassDataContract classContract)
int currentDataContractId = DataContractCriticalHelper.s_dataContractID;
for (int i = 0; i < currentDataContractId; i++)
{
if (ContractMatches(classContract, s_dataContractCache.GetItem(id)))
if (ContractMatches(classContract, s_dataContractCache.GetItem(i)))
{
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,21 @@ public static void DCS_Nullables()
Assert.Equal(item.Struct1.Value.B, actual.Struct1.Value.B);
}

[Fact]
public static void DCS_NullableDataContractStructAsRoot()
{
NullableRootDataContractStruct? value = new NullableRootDataContractStruct();
var serializer = new DataContractSerializer(typeof(NullableRootDataContractStruct?));

using var stream = new MemoryStream();
serializer.WriteObject(stream, value);

stream.Position = 0;
var roundTripped = (NullableRootDataContractStruct?)serializer.ReadObject(stream);

Assert.True(roundTripped.HasValue);
}

[Fact]
public static void DCS_SimpleStructWithProperties()
{
Expand Down Expand Up @@ -1545,6 +1560,11 @@ public static void DCS_PrivateTypeSerialization()
}

#region private type has to be in with in the class
[DataContract]
private struct NullableRootDataContractStruct
{
}

[DataContract]
private class PrivateType
{
Expand Down