如何解决错误“调用目标抛出了异常”

时间:2012-06-27 09:51:44

标签: c# wpf

当我运行以下代码时,它显示错误

  

“调用目标已抛出异常”

我该怎么做才能解决这个问题?

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 个答案:

答案 0 :(得分:0)

不应该是

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

两者都相同@"D:\Data.xml""D:\\Data.xml"