• 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

  • 相关阅读:
    Caliburn micro 学习笔记...
    First steps with Caliburn Micro in Windows Phone 8 系列文章
    WPF and Silverlight.ComboBox 如何通过 Binding IsDropDownOpen 实现下拉菜单展开
    http各个状态码的详解
    点阵字库产生的原理
    Windows 服务调试方法(基于.net framwork4.6)
    关于.net Core 笔记
    JS+ google.maps.api 实现基本的导航功能
    C# 遍历控件检查是否有被选中的项(通用)
    C#编程习惯
  • 原文地址:https://www.cnblogs.com/huangtailang/p/3031229.html
Copyright © 2020-2023  润新知