【问题标题】:how to solve error "Exception has been thrown by the target of an invocation"如何解决错误“调用的目标已引发异常”
【发布时间】:2012-06-27 09:51:44
【问题描述】:

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

“调用目标抛出异常”

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

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 
}

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    不应该

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

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

    【讨论】:

    • @"D\Data.xml""D:\\Data.xml"(后者没有 @
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多