-1

when I run the below code, it is showing the error

"Exception has been thrown by the target of an invocation"

What can i do to solve this issue?

public LinqToXml()
{
    XDocument document = XDocument.Load(@"D:\\Data.xml");
    #region Fetch All the Books
    var books = from r in document.Descendants("book") 
                select new
                {
                    Author = r.Element("author").Value,
                    Title = r.Element("title").Value,
                    Genere = r.Element("genre").Value,
                    Price = r.Element("price").Value,
                    PublishDate = r.Element("publish_date").Value,
                    Description = r.Element("description").Value,

                };

    foreach (var r in books)
    {
        com_xdocuments.Items.Add(r.PublishDate + r.Title + r.Author);                            

    }

    #endregion 
}
Yael
  • 1,566
  • 3
  • 18
  • 25
ASHOK A
  • 1,966
  • 3
  • 17
  • 31

1 Answers1

0

Shouldn't it be

XDocument document = XDocument.Load(@"D:\Data.xml");

Both are same @"D:\Data.xml" and "D:\\Data.xml"

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208