"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
Go Back  Xtreme Visual Basic Talk > > > "Data at the root level is invalid. Line 1, position 1."


Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2014, 06:56 AM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default "Data at the root level is invalid. Line 1, position 1."


I've never came across this error before.

I have a REST client and server. The client is just a simple test that allows you to click on buttons called GET, PUT, POST, DELETE and get a test message in return.

POST AND DELETE are fine, but when I click GET or PUT I get an error message in the GET1 or PUT1 catch with the error message in the title.


Code:
    Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
        ProcessRestPath(cboPath.Text)
        Try
            Dim rq As WebRequest
            Dim sr As IO.StreamReader
            Try
                rq = WebRequest.Create(cboPath.Text)
                ' Note - rq.Method is "GET" by default.
                sr = New IO.StreamReader(rq.GetResponse().GetResponseStream())
                txtValue.Text = FormatXML(sr.ReadToEnd())
                cboPath.Items.Add(cboPath.Text)
            Catch ex As Exception
                MessageBox.Show("Error in GET1: " & ex.Message)
            End Try
        Catch ex As Exception
            MessageBox.Show("Error in GET2: " & ex.Message)
        End Try
    End Sub

    Private Sub btnPut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPut.Click
        ProcessRestPath(cboPath.Text)
        Try
            Dim rq As HttpWebRequest
            Dim sr As IO.StreamReader
            Try
                rq = WebRequest.Create(cboPath.Text)
                rq.Method = "PUT"
                Dim rst As New IO.StreamWriter(rq.GetRequestStream())
                ' Send the headers...
                rst.WriteLine(txtValue.Text)
                rst.Close()
                sr = New IO.StreamReader(rq.GetResponse().GetResponseStream())
                cboPath.Items.Add(cboPath.Text)
                txtValue.Text &= ControlChars.NewLine & FormatXML(sr.ReadToEnd())
            Catch ex As Exception
                MessageBox.Show("Error in PUT1: " & ex.Message())
            End Try
        Catch ex As Exception
            MessageBox.Show("Error in PUT2: " & ex.Message)
        End Try
    End Sub
Reply With Quote
  #2  
Old 10-26-2014, 05:57 PM
dotnetwrassler dotnetwrassler is offline
Regular
 
Join Date: Sep 2014
Location: USA (Pacific/West Coast)
Posts: 71
Default Data at the root level is invalid. Line 1, position 1

Did you copy and paste the error into google?

I found a bunch of stackoverflow threads on this.

This stackoverflow thread suggests:
Quote:
..sometimes I get this error (line 1 col 1) in different applications because they stored in UTF-8 encoding and they have byte order mark at the very beginning of the text/file.
This stackoverflow thread said:
Quote:
I eventually figured out there was a byte mark exception and removed it.


In most of the other google results the xml in question (that is being read) is not what is called "well formed".

I noticed "FormatXML" calls in both your Get and Put codes Subs.

Maybe this is where non-well-formed XML is causing the error your are getting.

Just something to try:
You might try putting in some "half-step" troubleshooting code to read the raw xml text directly (and see what the xml looks like) before these lines are executed in your code:
Code:
txtValue.Text = FormatXML(sr.ReadToEnd())
Code:
txtValue.Text &= ControlChars.NewLine & FormatXML(sr.ReadToEnd())
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1." "Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
 
"Data at the root level is invalid. Line 1, position 1."
"Data at the root level is invalid. Line 1, position 1."
 
-->