Note that there are some explanatory texts on larger screens.

plurals
  1. PORESTSharp has problems deserializing XML including Byte Order Mark?
    primarykey
    data
    text
    <p>There is a public webservice which I want to use in a short C# Application: <a href="http://ws.parlament.ch/">http://ws.parlament.ch/</a></p> <p>The returned XML from this webservice has a "BOM" at the beginning, which causes RESTSharp to fail the deserializing of the XML with the following error message:</p> <blockquote> <p>Error retrieving response. Check inner details for more info. ---> System.Xml.XmlException: <strong>Data at the root level is invalid. Line 1, position 1.</strong> at System.Xml.XmlTextReaderImpl.Throw(Exception e)<br> at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)<br> at System.Xml.Linq.XDocument.Parse(String text) at RestSharp.Deserializers.XmlDeserializer.Deserialize[T](IRestResponse response) at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)<br> --- End of inner exception stack trace ---</p> </blockquote> <p>Here is an easy sample by using <a href="http://ws.parlament.ch/sessions?format=xml">http://ws.parlament.ch/sessions?format=xml</a> to get a List of '<em>Sessions</em>':</p> <pre><code>public class Session { public int Id { get; set; } public DateTime? Updated { get; set; } public int? Code { get; set; } public DateTime? From { get; set; } public string Name { get; set; } public DateTime? To { get; set; } } static void Main(string[] args) { var request = new RestRequest(); request.RequestFormat = DataFormat.Xml; request.Resource = "sessions"; request.AddParameter("format", "xml"); var client = new RestClient("http://ws.parlament.ch/"); var response = client.Execute&lt;List&lt;Session&gt;&gt;(request); if (response.ErrorException != null) { const string message = "Error retrieving response. Check inner details for more info."; var ex = new ApplicationException(message, response.ErrorException); Console.WriteLine(ex); } List&lt;Session&gt; test = response.Data; Console.Read(); } </code></pre> <p>When I first manipulate the returned xml with Fiddler to remove the first 3 bits (the "BOM"), the above code works! May someone please help me to handle this directly in RESTSharp? What am I doing wrong? THANK YOU in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload