Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:54:20+00:00 2026-06-11T01:54:20+00:00

I have the following XML response I am trying to deserialize using XmlSerializer. When

  • 0

I have the following XML response I am trying to deserialize using XmlSerializer. When I remove the call to XML serializer I throw no errors. Every time I use XmlSerializer I get
an exception. What am I missing?

Exception is:

System.Xml.XmlException: Root element is missing.
  at System.Xml.XmlTextReaderImpl.Throw(Exception e)
  at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
  at System.Xml.XmlTextReaderImpl.Read()
  at System.Xml.XmlTextReader.Read()
  at System.Xml.XmlReader.MoveToContent()
  at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSubmitReportResponse.Read5_NeweggAPIResponse()

Xml Doc is:

<?xml version="1.0" encoding="utf-8"?>
<NeweggAPIResponse>
    <IsSuccess>true</IsSuccess>
    <OperationType>OrderListReportResponse</OperationType>
    <SellerID>myID</SellerID>
    <ResponseBody>
        <ResponseList>
            <ResponseInfo>
                <RequestId>XXXXXXXX</RequestId>
                <RequestType>ORDER_LIST_REPORT</RequestType>
                <RequestDate>07/26/2012 09:27:06</RequestDate>
                <RequestStatus>SUBMITTED</RequestStatus>
            </ResponseInfo>
        </ResponseList>
    </ResponseBody>
</NeweggAPIResponse>

My call to XmlSerializer is:

XmlSerializer serializer = new XmlSerializer(typeof(SubmitReportResponse));
reportReq = serializer.Deserialize(respStream) as SubmitReportResponse;

SubmitReportResponse class is:

    public enum RequestStatus
{
    ALL,
    SUBMITTED,
    IN_PROGRESS,
    FINISHED,
    CANCELLED
}

/// <summary>
/// TODO: Update summary.
/// </summary>
[XmlRoot("NeweggAPIResponse")]
public class SubmitReportResponse
{
    public string IsSuccess { get; set; }
    public string OperationType { get; set; }
    public string SellerID { get; set; }
    public ReportResponseBody ResponseBody { get; set; }

    public SubmitReportResponse()
    {
        ResponseBody = new ReportResponseBody();
    }
}

public class ReportResponseBody
{
    public string Memo { get; set; }
    public ReportResponseList[] ResponseList { get; set; }   



    public ReportResponseBody()
    {

        ResponseList = new ReportResponseList[0];
    }
}

public class ReportResponseList
{
    public ResponseInfo[] ResponseInfo { get; set; }

    public ReportResponseList()
    {
        ResponseInfo = new ResponseInfo[0];
    }

}

public class ResponseInfo
{
    public string RequestId { get; set; }
    public string RequestType { get; set; }
    public string RequestDate { get; set; }
    public RequestStatus RequestStatus { get; set; }

    public ResponseInfo()
    {
        RequestStatus = new RequestStatus();
    }
}

EDIT:

Requesting Code:

            HttpWebRequest request = WebRequest.Create(endpoint) as HttpWebRequest;
            request.Proxy = null;
            request.Method = "POST";
            //Specify the xml/Json content types that are acceptable. 
            request.ContentType = "application/xml";
            request.Accept = "application/xml";

            //Attach authorization information
            request.Headers.Add("Authorization", apikey);
            request.Headers.Add("Secretkey", secretkey);

            GetOrderListRequest requestObj = new GetOrderListRequest();
            requestObj.OperationType = OperationType.OrderListReportRequest;
            requestObj.RequestBody = new OrderListRequestBody();
            requestObj.RequestBody.OrderReportCriteria = new OrderReportCriteria();
            requestObj.RequestBody.OrderReportCriteria.Status = 3;
            requestObj.RequestBody.OrderReportCriteria.KeywordsType = 0;
            requestObj.RequestBody.OrderReportCriteria.OrderDateFrom = "2012-01-01";
            requestObj.RequestBody.OrderReportCriteria.OrderDateTo = "2012-07-26";
            requestObj.RequestBody.OrderReportCriteria.OrderDownloaded = "false";

            string requestBody = SerializeToString(requestObj);

            byte[] byteStr = Encoding.UTF8.GetBytes(requestBody);
            request.ContentLength = byteStr.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(byteStr, 0, byteStr.Length);
            }

            //Parse the response
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                //Business error
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Console.WriteLine(string.Format("Error: response status code is{0}, at time:{1}", response.StatusCode, DateTime.Now.ToString()));

                    return;
                }
                else if (response.StatusCode == HttpStatusCode.OK)//Success
                {
                    using (Stream respStream = response.GetResponseStream())
                    {
                        StreamReader readerOK = new StreamReader(respStream);
                        //Console.WriteLine(String.Format("Result:{0}", DateTime.Now.ToString()));
                        Console.WriteLine(String.Format("{0}", readerOK.ReadToEnd()));

                        XmlSerializer serializer = new XmlSerializer(typeof(SubmitReportResponse));
                        reportReq = serializer.Deserialize(respStream) as SubmitReportResponse;
                    }
                }
            }


    public string SerializeToObj(object obj)
    {

        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
        ns.Add("", "");
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.OmitXmlDeclaration = true;
        settings.Encoding = new UTF8Encoding(false);
        settings.Indent = true;
        XmlSerializer xs = new XmlSerializer(obj.GetType());
        MemoryStream ms = new MemoryStream();

        // xs.Serialize(ms, obj,ns);


        XmlWriter writer = XmlWriter.Create(ms, settings);
        xs.Serialize(writer, obj, ns);

        return Encoding.UTF8.GetString(ms.ToArray());
    }

Resolution:

It seems that calling Console.WriteLine(String.Format("{0}", readerOK.ReadToEnd())); causes the stream to be consumed and be unavailable for serialization. Removing this line allowed me to properly serialize the XML into my classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:54:22+00:00Added an answer on June 11, 2026 at 1:54 am

    Calling Console.WriteLine(String.Format("{0}", readerOK.ReadToEnd())); causes the stream to be consumed and be unavailable for serialization.

    Removing this line allowed me to properly serialize the XML into my classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following xml as a response to a service not i want to
I have following XML. I was able to remove all namespaces but not able
I have the following xml I need to read the values of: <po-response xmlns=http://test.com<
I am trying to generate the following XML in my SOAP call: <CResponse> <ID>int</ID>
I have an xml document with the following format: <response username=123 customerName=CustomerName siteName=SiteName customerID=123
I have the following XML: <response> <propertySearchSales> <properties rentalperiod=0><pages page=1 count=153 pageCount=16 perPage=10> <pages
I have the following XML output from an API <?xml version='1.0' encoding='UTF-8'?> <Response> <ReturnRow
I am trying to deserialize the following xml structure into an object... <?xml version=1.0
I am trying to retrieve an XML response using ajax calls to the eXist
I have following xml and I want to fetch the value of node which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.