Click here to Skip to main content
14,451,560 members
Rate this:
Please Sign up or sign in to vote.
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)

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] = "";
          client.Headers[HttpRequestHeader.Cookie] = sessioncookie;
          byte[] response = client.UploadData("**********", Encoding.UTF8.GetBytes(requestJson));
          responseJson = Encoding.UTF8.GetString(response);

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

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?
Updated 14-Oct-15 20:51pm
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100