我的错误在C#和idk中,为什么它告诉我找不到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");
}
}
}
}
}
答案 0 :(得分:1)
确保 System.Xml 作为参考包含在您的项目中,并为其添加了正确的using语句。