System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'

-- -- 957 Reputation points
2022-02-26T06:04:04.903+00:00

Hi

I am using code below at the end to query an OData v4 service. The data is returned fine however when I try to iterate through it using;

foreach (var client1 in clients)  

I get an 'System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'' error.

How can I fix the issue? Why is it checking for xml when the data is retuned as json?

I am using Micorsoft OData Connected Service to generate classes and plumbing for OData client.

Thanks

Regards

        var serviceRoot = "http://localhost:65202/api/odata/";  
        var context = new Container(new Uri(serviceRoot));  

        context.BuildingRequest += Context_BuildingRequest;  

        var clients = context.Clients.Where(c => c.ID >= 0 & c.ID <= 100)  
                                     .OrderByDescending(p => p.ID)  
                                     .Select(c => new { c.Company, c.ID });  

        foreach (var client1 in clients)  
        {  
            Console.WriteLine("{0} {1}", client1.Company, client1.ID);  
        }  
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bengt Steffens 1 Reputation point
    2022-09-15T14:03:47.127+00:00

    experiencing precisely this error.
    nothing can be found but this page.

    @-- -- could you please help and share any results or a follow up link to github?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.