4

I am having problems saving serialized data from a nested custom class list. How do you properly serialize these classes?

[System.Serialize]
public class OuterClass() {
  List<InnerClass> someList = new List<InnerClass>();
  public OuterClass() {}
}
public class InnerClass() {
  public int someInt;
  public InnerClass(int _someInt) {
    someInt = _someInt;
  }
}

3 Answers 3

2

Mark both your class with the [Serializable] attribute

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer, that does solve one of the problems in my serialization code. However, it seems that the issue runs deeper. Follow-up question here: stackoverflow.com/questions/10362513/…
0

The InnerClass class should have the [System.Serialize] attribute as well to be able to serialize it. Something along these lines:

[System.Serialize]
public class OuterClass() {
  List<InnerClass> someList = new List<InnerClass>();

  [System.Serialize]
  public class InnerClass() {
    public int someInt;
  }
}

On a side note, your InnerClass is not nested. It should be defined inside the OuterClass if you want to call it "nested class"

Comments

0

Both the containing and the contained class must be decorated with the [Serializable] attribute.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.