CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Error in XML

  1. #1
    Join Date
    Aug 2011
    Posts
    0

    Error in XML

    Hi, I'm using .net 4.0

    I'm trying to use serialization to save my array of monster and got this error:

    An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll

    Additional information: There was an error generating the XML document.



    Here's my code:

    public void Save()
    {
    using (IsolatedStorageFile saveGameFile = IsolatedStorageFile.GetUserStoreForApplication())
    using (IsolatedStorageFileStream SaveGameStream = new IsolatedStorageFileStream("monster.dat", FileMode.OpenOrCreate, saveGameFile))
    {
    XmlSerializer serializer = new XmlSerializer(typeof(List<Monster>));
    serializer.Serialize(SaveGameStream, _lMonster);
    }
    }

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Error in XML

    Nothing looks obviously wrong upon code review (though obviously there is since it throw an exception...)

    Which line throws the exception? I assume the call to serializer.Serialize(...)?

    Failing that, is there a reason you are using XMLSerialization? Why not give binary serialization a try? It's slightly more challenging to implement, but offers some benefits.

    Tutorial: http://www.codeproject.com/KB/cs/objserial.aspx

    Sorry I can't be of more help!
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured