zoukankan      html  css  js  c++  java
  • 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.InvalidOperationException Message
    ="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.XmlException Message="缺少根元素。" Source="System.Xml" LineNumber=0 LinePosition=0 SourceUri="" 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

  • 相关阅读:
    QQ机器人
    MySQL Hash索引和B-Tree索引的区别
    python format
    Python csv模块的使用
    Python 随机数函数
    关于Python Profilers性能分析器
    数据结构之排序算法Java实现(6)—— 插入类排序之折半插入排序算法
    数据结构之排序算法Java实现(5)—— 插入类排序之直接插入排序算法
    数据结构之排序算法Java实现(4)—— 交换类排序之快速排序算法
    数据结构之排序算法Java实现(3)—— 交换类排序之冒泡排序算法
  • 原文地址:https://www.cnblogs.com/huangtailang/p/3031229.html
Copyright © 2011-2022 走看看