i m trying to return list<object> from webmethod but gives error
- by girish
System.InvalidOperationException: There was an error generating the XML document. --- System.InvalidOperationException: The type WebService.Property.Property_Users was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write8_ArrayOfAnyType(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ListOfObjectSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
public List<object> GetDataByModuleName(string ModuleName)
{
List<Property_Users> obj_UserList = new List<Property_Users>();
// performing some operation that add data to obj_UserList
List < Object > myList = new List<object>();
return ConvertToObjectList<Property_Users>(obj_UserList);
}
public List<Object> ConvertToObjectList<N>(List<N> sourceList)
{
List<Object> result = new List<Object>();
foreach (N item in sourceList)
{
result.Add(item as Object);
}
return result;
}
[WebMethod]
public List<object> GetDataByModuleName(string ModuleName)
{
List<object> obj_list = new List<object>();
obj_list = BAL_GeneralService.GetDataByModuleName(ModuleName);
return obj_list;
}