找不到 XmlTextReader/XmlNodeType 命名空间,如何解决?

Posted

技术标签:

【中文标题】找不到 XmlTextReader/XmlNodeType 命名空间,如何解决?【英文标题】:XmlTextReader/XmlNodeType namespace could not be found, how to fix? 【发布时间】:2015-12-23 20:18:32 【问题描述】:

我的错误在 C# 中,我知道为什么它告诉我找不到 XmlTextReader 命名空间。我必须与XmlNodeType 相同的错误说它找不到。我该如何解决?

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Updater

    class Program
    
        static void Main(string[] args)
        
            string downloadUrl = " ";
    Version newVersion = null;
    string xmlUrl = "http://www.mywebsite.com";
    XmlTextReader reader = null; //The error here says that XmlTextReader could not be found
    try
    
        reader = new XmlTextReader(xmlUrl);
        reader.MoveToContent();
        string elementName = " ";
        if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "EastPerlUpdater")) //XmleNodeType is another error that shows saying doesnt exist in current context, but its all over the place!!
        
            while(reader.Read())
            
                if(reader.NodeType == XmlNodeType.Element) //Again with the XmlNodeType error, and so on.
                
                    elementName = reader.Name;
                

                else
                
                    if((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                    
                        switch(elementName)
                        
                            case "version":
                            newVersion = new Version(reader.Vaule);
                            break;
                            case "url":
                            downloadUrl = reader.Vaule();
                            break;
                        
                    
                
            
        
    
    catch (Exception ex)
    

    Console.WriteLine(ex.Message);
    Environment.Exit(1);

    
    finally
    
        if (reader != null)
            reader.Close();
    
    Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
    if (applicationVersion.CompareTo(newVersion) < 0)
    
        Console.WriteLine("Version " + newVersion.Major + "." + newVersion.Minor + "." + newVersion.Build + "A new version of East Perl Hub is available, want to download? Y/N");
        string userInput = Console.ReadLine();
        if (userInput == "Y")
        
            System.Diagnostics.Process.Start(downloadUrl);
        

        else
    
        Console.WriteLine("This app is up to date");
    

    
        
    

【问题讨论】:

【参考方案1】:

确保 System.Xml 作为参考包含在您的项目中,并且您为其添加了正确的 using 语句。

【讨论】:

好吧,我会被诅咒的,我知道我是多么想念它。非常感谢!

以上是关于找不到 XmlTextReader/XmlNodeType 命名空间,如何解决?的主要内容,如果未能解决你的问题,请参考以下文章

java 枚举 找不到符号

bat系统找不到指定文件怎么办?

java package找不到符号

SpringBoot报找不到 dao 问题

ubuntu20.04找不到start命令

找不到名为“my”的模块。找不到名为“mycontroller”的控制器