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