-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 
}
0

1 Answer 1

0

Shouldn't it be

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

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

1
  • @"D\Data.xml" and "D:\\Data.xml" (no @ in the latter) Jun 27, 2012 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.