Click here to Skip to main content
15,867,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Newtonsoft.Json.Linq.JToken does not implement Add(System.Object)

C#
using (WebClient client = new WebClient())
      {
          client.Headers[HttpRequestHeader.Accept] = "application/json, text/javascript, */*; q=0.01";
          client.Headers[HttpRequestHeader.ContentType] = "application/json";
          client.Headers[HttpRequestHeader.Referer] = "https://rateinvent.com";
          client.Headers[HttpRequestHeader.Cookie] = sessioncookie;
          byte[] response = client.UploadData("**********", Encoding.UTF8.GetBytes(requestJson));
          responseJson = Encoding.UTF8.GetString(response);

          obj = JsonConvert.DeserializeObject<RoomAvail>(responseJson);
       }


XML
public class RoomAvail
{
    public string eventList { get; set; }
    public string lastCalledNumber { get; set; }
    public string serverTime { get; set; }
    public string errorDetails { get; set; }
    public long maxValidityDate { get; set; }

    public RoomAvail()
    {
        roomDetailsList = new List<roomDetailsList>();
    }

    public List<roomDetailsList> roomDetailsList { get; set; }

}

public class roomDetailsList
{

    public string roomName { get; set; }

    public roomDetailsList()
    {
        tariffSetList = new List<List<tariffSetList>>();
    }
    public List<List<tariffSetList>> tariffSetList { get; set; }

    public string roomSeqNo { get; set; }


}


when i calling this method to webservice i got above error?
Posted
Updated 14-Oct-15 19:51pm
v2
Comments
Sinisa Hajnal 15-Oct-15 6:52am    
Go to Newtonsoft site and report the error there. For the time being you'll have to find a way to avoid the use of JToken.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900