asp.net - How to serialize to XML an ArrayList -


i having trouble serializing arraylist xml in .net. using asp mvc , created class extends actionresult

public class xmlresult : actionresult {     private readonly object _data;      public xmlresult(object data)     {         _data = data;     }      public override void executeresult(controllercontext context)     {         if (_data != null)         {             var response = context.httpcontext.response;             response.contenttype = "text/xml";             var serializer = new xmlserializer(_data.gettype(), "assignment2.models.bl.book");              serializer.serialize(response.outputstream, _data);         }     } } 

now _data arraylist of reportfvo

using system; using system.collections.generic; using system.linq; using system.web; using system.xml.serialization;  namespace assignment2.models.bl.book {     [xmlinclude(typeof(reportfvo))]     public class reportfvo     {         public string title { get; set; }         public string author { get; set; }         public string first_name { get; set; }                 public string last_name { get; set; }          public reportfvo()         {             this.title = "";             this.author = "";             this.first_name = "";             this.last_name = "";         }     } } 

every time xmlresult called exception saying "the type assignment2.models.bl.book.reportfvo not expected. use xmlinclude or soapinclude attribute specify types not known statically.". out of ideas. how fix this? in advance.

why using arraylist? that's sooo deprecated since introduction of generics. use reportfvo[] or list<reportfvo> instead. alternative may try following:

var serializer = new xmlserializer(_data.gettype(), new type[] { typeof(reportfvo) }); 

Comments