-1

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

“调用的目标已抛出异常”

我能做些什么来解决这个问题?

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

1 回答 1

0

难道不应该

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

两者都是一样@"D:\Data.xml""D:\\Data.xml"

于 2012-06-27T09:58:13.363 回答