You've run into one of the DataContractSerializer
gotchas.
Fix: Change your private member declaration to:
[DataMember]
private List<Person> members = new List<Person>();
OR change the property to:
[DataMember()]
public IList<Person> Feedback {
get { return m_Feedback; }
set {
if ((value != null)) {
m_Feedback = new List<Person>(value);
} else {
m_Feedback = new List<Person>();
}
}
}
And it will work. The Microsoft Connect bug is here
This problem occurs when you deserialize an object with an IList<T>
DataMember and then try to serialize the same instance again.
If you want to see something cool:
using System;
using System.Collections.Generic;
class TestArrayAncestry
{
static void Main(string[] args)
{
int[] values = new[] { 1, 2, 3 };
Console.WriteLine("int[] is IList<int>: {0}", values is IList<int>);
}
}
It will print int[] is IList<int>: True
.
I suspect this is possibly the reason you see it come back as an array after deserialization, but it is quite non-intuitive.
If you call the Add() method on the IList<int>
of the array though, it throws NotSupportedException
.
One of those .NET quirks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…