我正在尝试使用 C# 在 Windows CE 中加载 XML 文档,但是在调试过程中我不断遇到一些奇怪的错误。这是我的代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace cpap3
{
public class Program
{
public static void Display()
{
XmlDocument docXML = new XmlDocument();
docXML.Load(Environment.GetFolderPath(Environment.SpecialFolder.Programs)+"\\modulos.xml");
XmlElement nodRoot = docXML.DocumentElement;
XmlNodeList nodItems = nodRoot.GetElementsByTagName("Modulos");
for (int i = 0; i < nodItems.Count; i++)
Console.WriteLine(nodItems[i].InnerXml);
for (int i = 0; i < nodItems.Count; i++)
Console.WriteLine(nodItems[i].InnerXml);
}
static int Main(string[] args)
{
Display();
return 0;
}
}
}
我做错了什么吗? XML 文件位于正确的位置,并且我已经尝试了该文件的多个位置。这是我收到的错误。
{“无法显示错误消息,因为找不到包含它的可选资源程序集。无法显示错误消息,因为找不到包含它的可选资源程序集”}
加载 XML 文件时出现错误:
docXML.Load(Environment.GetFolderPath(Environment.SpecialFolder.Programs)+"\modulos.xml");
这是异常详细信息:
System.Xml.XmlException was unhandled
Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found An error message cannot be displayed because an optional resource assembly containing it cannot be found"
LineNumber=1
LinePosition=31
SourceUri="file:///Windows/Programs/modulos.xml"
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw()
at System.Xml.XmlTextReaderImpl.Throw()
at System.Xml.XmlTextReaderImpl.CheckEncoding()
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load()
at System.Xml.XmlDocument.Load()
at System.Xml.XmlDocument.Load()
at ConsoleApplication3.Program.Display()
at ConsoleApplication3.Program.Main()
---------------编辑--------------
我花了一段时间,但现在我有了真正的错误报告:)...这是实际的错误。
"System does not support 'iso-8859-1' encoding. Line 1, position 31."
我尝试使用不同的编码保存我的文件,但我不断收到相同的错误。有什么解决办法吗?
---------------编辑----------------- 我已经解决了:D。我正在使用记事本更改编码,但我忘记了我在 XML 文件中写入了编码标记,这导致了此问题。愚蠢的错误。 :(
最佳答案
好吧,实际上您必须与构建 WinCE 操作系统镜像的人交谈,以包含“.Net Compact Framework 3.5 本地化字符串资源”,默认情况下您将拥有 en-US,但您也可以选择其他内容,例如:葡萄牙语。该选项位于目录项 View -> 核心操作系统 -> Windows Embedded Compact -> 应用程序和服务开发 -> .NET Compact Framework 3.5 -> .Net Compact Framework 3.5 -> .Net Compact Framework 3.5 本地化字符串资源
见附图:
如果您使用的是操作系统镜像,则还必须重新制作 SDK。此后您应该不会再出现此错误。
关于c# - 使用 C# 在 Windows CE 中加载 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7443763/