I am trying to return List type from a web service. I have used a similar version from here.
I get the following error:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.
Code:
[WebMethod]
public List<object> getnpsTrend(string region, string client, string product)
{
List<object> iData = new List<object>();
List<string> labels = new List<string>();
labels.Add ("test1");
iData.Add(labels);
return iData;
}
Thanks for your help in advance!
Update: After hours of struggling, i have found out that it does not work only when my list object contains another complex object (like array / another list). It works works otherwise. The following code yields perfect result.
[WebMethod]
public List<Object> getnpsTrend()
{
List<Object> li = new List<object>();
string obj = "Test";
li.Add(obj);
return li ;
}
But I need a list containing list to be the return type. Is there any way I can create a user defined type with the required structure, that will be serializable by xml ?