locked
Problem serializing XDocument

    问题

  • Hello!

    I'm creating XDocument manually:

    var doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));

    doc.Add(new XElement("Response"));

    But when I try to save it:

    var ms = new MemoryStream();
    doc.Save(ms);

    ...I receive this stupid message: "Token EndDocument in state Document would result in an invalid XML document".

    WHY in absolutely valid document I have this strange error?

    2012年8月10日 12:10

全部回复

  • Hi Vincent;

    I placed the following code into a project and it ran without issue.

    var doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"));
    doc.Add(new XElement("Response"));
    
    var ms = new MemoryStream();
    doc.Save(ms);

    Please post the actual code and on what line you receive the error. Also what version of Visual Studio and the .Net framework are you using?

      



    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    2012年8月10日 15:28
  • Hi Vincent,

    Could you please provide more specific information as Fernando mentioned?

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    2012年8月13日 2:36