Logo 
Search:

.Net Framework FAQ

Submit Interview FAQ
Home » Interview FAQ » .Net FrameworkRSS Feeds

Why am I getting an InvalidOperationException when I serialize an ArrayList?

  Shared By: Carl Woods    Date: Dec 13    Category: .Net Framework    Views: 1118

Answer:

XmlSerializer needs to know in advance what type of objects it will find in an ArrayList. To specify the type, use the XmlArrayItem attibute like this:

public class Person
{
public string Name;
public int Age;
}

public class Population
{
[XmlArrayItem(typeof(Person))] public ArrayList People;
}

Share: 
 



Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].