web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Data at the root level is invalid. Line 1, position 1

(0) ShareShare
ReportReport
Posted on by 445

Hello,

i try to read a XML file in C# but everytime i got the Error "Data at the root level is invalid. Line 1, position 1."

I dont know how to fix it. Can anyone help me?

This is my code:

                        if ((filename.ToLower() == "lead.xml" || filename.ToLower() == "lead.xml.xml") && ent.Attributes.Contains("body"))//aktualisieren
                        {
                            byte[] data = Convert.FromBase64String(ent.Attributes["body"].ToString());
                            string xml = Encoding.UTF8.GetString(data);



                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(xml);
                            doc.PreserveWhitespace = false;
                            XmlNode root = doc.DocumentElement;

                            tracingService.Trace("läuft2");

                            foreach (XmlNode node in root)
                            {
                                if (node.Name == "recipient")
                                {...


*This post is locked for comments

I have the same question (0)
  • Verified answer
    SergeyT Profile Picture
    310 on at

    Hi.

    It may be UTF BOM mark. More solutions here: stackoverflow.com/.../xml-loaddata-data-at-the-root-level-is-invalid-line-1-position-1

  • BlackBeard Profile Picture
    445 on at

    Yes!

    It works B-)

    Thank you!

  • karthikeyani c Profile Picture
    190 on at

    Hi All,

    Can this be applied for Al code which connects Business Central ?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans