What’s wrong with the following code?
MyList l = Serializer.DeepClone(new MyList { "abc" });
Console.WriteLine(l.Count == 1);
Where:
[ProtoContract]
public class MyList : List<String>
{
}
Expected: true, actual: false.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want an immediate fix, just take away the
[ProtoContract]; lists have inbuilt behaviour, and don’t need to be marked as contracts.It looks like in this case the contract definition is taking precedence over the fact that it is a list; I will need to look carefully to see if changing this causes any unwanted side-effects.
Working example:
currently broken example:
Update; however, it looks like this should work, since it works fine when the list is a member of a type; the problem only occurs when the list is the outermost type in a graph. Example (all tests pass):
Update update: this was a subtle bug, caused by the many different ways that lists can behave; in the case of lists as members that have getters and setters, it has some logic that says “if we get the list, and it wasn’t null, don’t call the setter – just add”. However, the code that handles types-that-are-lists was accidentally enabling that mode. So what was happening was: it would deserialize the data, then proclaim “you can discard this value” – which it dutifully did. Then the “never return null” code would just create a new list, and return that instead. Annoyingly, just a one-liner to fix, and no side-effects; fixed in r555.
Whenever someone gets stuck, I add an integration test; so this shouldn’t happen again