XML document (0, 0) has an error. The root element is missing.

Source: Internet
Author: User
 

 

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 not processed = " XML document (0, 0) has an error. " Source = " System. xml " Stacktrace: in system. XML. serialization. xmlserializer. deserialize (xmlreader, string encodingstyle, xmldeserializationevents events) in system. XML. serialization. xmlserializer. deserialize (Stream stream) in nflicense. class1.load [T] (fileinfo file) Location E: \ hy \ www \ ABC \ test. CS: row number 131 In nflicense. class1.load (string filename) Location E: \ hy \ www \ ABC \ test. CS: row number 209 In nflicense. class1.validate (string linesepath, string pubkey, string productname, string username) Location E: \ hy \ www \ nfcrm \ ABC \ test. CS: row number 217 In nfcrm. program. Main (string [] ARGs) Location E: \ hy \ www \ nfcrm \ ABC \ Program. CS: row number 22 In system. appdomain. _ nexecuteassembly (Assembly, string [] ARGs) in system. appdomain. executeassembly (string assemblyfile, evidence assemblysecurity, string [] ARGs) in Microsoft. visual Studio. hostingprocess. hostproc. runusersassembly () in system. threading. threadhelper. threadstart_context (Object State) in system. threading. executioncontext. run (executioncontext, contextcallback callback, object state) in system. threading. threadhelper. threadstart () innerexception: system. XML. xmlexception message = " The root element is missing. " Source = " System. xml " Linenumber = 0 Lineposition = 0 Sourceuri = "" Stacktrace: in system. XML. xmltextreaderimpl. throw (exception E) in system. XML. xmltextreaderimpl. throwwithoutlineinfo (string res) in system. XML. xmltextreaderimpl. parsedocumentcontent () in system. XML. xmltextreaderimpl. read () in system. XML. xmltextreader. read () in system. XML. xmlreader. movetocontent () in Microsoft. XML. serialization. generatedassembly. xmlserializationreaderlicense. read3_license () innerexception:

 

 

Solution:

Before serialization, add:

Ms. Position = 0;

Function t validate (StringStr ){Using(Memorystream MS =NewMemorystream ()){Foreach(Byte_ ByteInEncoding. Default. getbytes (STR) {Ms. writebyte (_ byte);} result= (T)NewXmlserializer (Typeof(T). deserialize (MS); Ms. Close ();}}

 

Solution Source: http://www.cnblogs.com/nikytwo/archive/2009/03/27/1423032.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.