How to solve the error "Exception was selected as the target of the call"

when I run the code below it shows an error

"Exception selected by call target"

What can I do to solve this problem?

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 
}
-1
source share
1 answer

Must not be

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

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

0
source

Source: https://habr.com/ru/post/1629515/


All Articles