XmlTextReader/XmlNodeType 找不到命名空间,如何解决?
XmlTextReader/XmlNodeType namespace could not be found, how to fix?
我的错误在 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");
}
}
}
}
}
确保 System.Xml 包含在您的项目中作为参考,并且您为它添加了正确的 using 语句。
我的错误在 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");
}
}
}
}
}
确保 System.Xml 包含在您的项目中作为参考,并且您为它添加了正确的 using 语句。