XML 文档(0, 0)中有错误。缺少根元素。
生活随笔
收集整理的這篇文章主要介紹了
XML 文档(0, 0)中有错误。缺少根元素。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
function T Validate(string str){
using (MemoryStream ms = new MemoryStream())
{
foreach (byte _byte in Encoding.Default.GetBytes(str))
{
ms.WriteByte(_byte);
}
result = (T)new XmlSerializer(typeof(T)).Deserialize(ms);
ms.Close();
}
}
未處理 System.InvalidOperationExceptionMessage="XML 文檔(0, 0)中有錯誤。"Source="System.Xml"StackTrace:在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)在 System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)在 NFLicense.Class1.Load[T](FileInfo file) 位置 E:\hy\WWW\abc\test.cs:行號 131在 NFLicense.Class1.Load(String fileName) 位置 E:\hy\WWW\abc\test.cs:行號 209在 NFLicense.Class1.Validate(String linesepath, String pubkey, String productname, String username) 位置 E:\hy\WWW\NFCRM\abc\test.cs:行號 217在 NFCRM.Program.Main(String[] args) 位置 E:\hy\WWW\NFCRM\abc\Program.cs:行號 22在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)在 System.Threading.ThreadHelper.ThreadStart()InnerException: System.Xml.XmlExceptionMessage="缺少根元素。"Source="System.Xml"LineNumber=0LinePosition=0SourceUri=""StackTrace:在 System.Xml.XmlTextReaderImpl.Throw(Exception e)在 System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)在 System.Xml.XmlTextReaderImpl.ParseDocumentContent()在 System.Xml.XmlTextReaderImpl.Read()在 System.Xml.XmlTextReader.Read()在 System.Xml.XmlReader.MoveToContent()在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderLicense.Read3_License()InnerException:
?
?
解決辦法:
在序列化之前加:
ms.Position = 0;
function T Validate(string str){using (MemoryStream ms = new MemoryStream()) { foreach (byte _byte in Encoding.Default.GetBytes(str)) { ms.WriteByte(_byte); }result = (T)new XmlSerializer(typeof(T)).Deserialize(ms); ms.Close(); }}?
解決辦法來源:http://www.cnblogs.com/nikytwo/archive/2009/03/27/1423032.html
轉載于:https://www.cnblogs.com/huangtailang/archive/2013/04/19/3031229.html
總結
以上是生活随笔為你收集整理的XML 文档(0, 0)中有错误。缺少根元素。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 挖掘管理价值:企业软件项目管理实战
- 下一篇: Mysql Replication 机制