Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 这种例外情况是如何产生的,可以采用什么替代方案?_C#_Linq_Namespaces_Rss - Fatal编程技术网

C# 这种例外情况是如何产生的,可以采用什么替代方案?

C# 这种例外情况是如何产生的,可以采用什么替代方案?,c#,linq,namespaces,rss,C#,Linq,Namespaces,Rss,发现一个我不理解的异常。如果有人愿意的话,我真的很想得到一些帮助。使用其他经过测试的RSS源,并且没有问题,但是最新的测试候选人让我头疼 Line 499 is the one in the query: select new { Line 517 is the opening statement of the foreach. --在System.Xml.Linq.XNamespace.op_AdditionXNamespace ns中,字符串localName位于 rssRepub.Mai

发现一个我不理解的异常。如果有人愿意的话,我真的很想得到一些帮助。使用其他经过测试的RSS源,并且没有问题,但是最新的测试候选人让我头疼

Line 499 is the one in the query: select new {
Line 517 is the opening statement of the foreach.
--在System.Xml.Linq.XNamespace.op_AdditionXNamespace ns中,字符串localName位于 rssRepub.MainForm.c__显示类d.b__2XElement项 c:\Documents and Settings\Andrew Seabrook\My Documents\development\rssPub\rssRepub_0.5\rssRepub\MainForm.cs:line 499 at System.Linq.Enumerable。其中选择EnumerableInterator`2.MoveNext 在rssRepub.MainForm.CompletedObject发送方,AsyncCompletedEventArgs c:\Documents and Settings\Andrew Seabrook\My中的e Documents\development\rssPub\rssRepub_0.5\rssRepub\MainForm.cs:line 517

--值不能为null。参数名称:ns


您能否突出显示引发异常的行和导致异常的示例RSS提要?这里dcNs和SLA的值是多少?它们是空的吗?或非空?@T.Kiley它在foreach行上跳闸。feed是-我注意到,与此feed不同的是,标记具有属性purl.org/rss/1.0/modules/slash/>0和purl.org/dc/elements/1.1/>Esme wheras前面的那些是simple@marcgravel是的,它们确实是空的,我是在这个问题上抛出的,因为错误提到的是通用的“ns”,而不是特定的slashNs或dcNs-愚蠢的“那么,我需要以不同的方式处理这件事吗?”安德鲁斯·亚布鲁克:是的;通常,您可以对名称空间进行硬编码。。。
        try
        {                       

            toolStripStatusLabelMain.Text = "Download completed!";
            XslCompiledTransform transform = new XslCompiledTransform();
            transform.Load(INSTALLPATH + "id.xslt");
            transform.Transform(INSTALLPATH + "tempfeed.txt", INSTALLPATH + "clean.xml");

            XDocument doc = XDocument.Load(INSTALLPATH + "clean.xml");

            Dictionary<String, String> dbdata = new Dictionary<String, String>();
            var db = new MSAccess();
            string feedID =  db.ExecuteScalar("SELECT feedID FROM Feeds WHERE feedURL = '" + tvMain.SelectedNode.Tag.ToString() + "'");


            XNamespace dcNs = doc.Element("rss").GetNamespaceOfPrefix("dc");
            XNamespace slashNs = doc.Element("rss").GetNamespaceOfPrefix("slash");
            //XNamespace slashNs = "http://purl.org/rss/1.0/modules/slash/";

            var data = from item in doc.Root.Descendants().First(i => i.Name.LocalName == "channel").Elements().Where(i => i.Name.LocalName == "item")
                      select new {
                            Title = item.Elements().First(i => i.Name.LocalName == "title").Value,
                            Link = item.Elements().First(i => i.Name.LocalName == "link").Value,
                            PublishDate = ParseDate(item.Elements().First(i => i.Name.LocalName == "pubDate").Value),
                            Creator = item.Element(dcNs + "creator").Value,
                            Guid = item.Elements().First(i => i.Name.LocalName == "guid").Value,                
                            Description = item.Elements().First(i => i.Name.LocalName == "description").Value,
                            //Content = item.Elements().First(i => i.Name.LocalName == "content").Value,
                            Content = item.Elements().First(i => i.Name.LocalName == "description").Value,
                            //Comments = item.Element("slash:comments").Value
                            Comments = item.Element(slashNs + "comments").Value,
                            //Comments = item.SelectSingleNode("slash:comments", nameSpace).InnerText
                            Categories = (from category in item.Elements("category")
                                          orderby category.Value
                                          select category.Value).ToList()

            };

            foreach (var item in data)
            {

                var csv = string.Join( ";", item.Categories );

                //add feed to database
                dbdata.Add("fiFeedID", feedID);
                dbdata.Add("fiTitle", item.Title);
                dbdata.Add("fiLink", item.Link);
                dbdata.Add("fiPubDate", item.PublishDate.ToString());
                //if (item.Creator != null) 
                dbdata.Add("fiCreator", item.Creator);
                dbdata.Add("fiGuid", item.Guid);
                dbdata.Add("fiDescription", item.Description);                  
                dbdata.Add("fiContent", item.Content);  
                //if (item.Comments != null) 
                dbdata.Add("fiComments", item.Comments);
                dbdata.Add("fiTags",csv);

                try
                {
                    db.Insert("FeedItems", dbdata);
                }
                catch(Exception crap)
                {
                    OutCrap(crap);
                } 
                dbdata.Clear();

            }
            UpdateStatus("Fetching " + tvMain.SelectedNode.Name);
            UpdateDGVMain();
        }
        catch (Exception crap)
        {
            OutCrap(crap);
        }