Forum Libraries, Components, and Plugins

Serializing my Player class to xml

I'm attempting to serialize my Player class to XML:

        XmlSerializer x = new XmlSerializer (activePlayer.GetType ());
        using (StreamWriter myWriter = new StreamWriter ("playerdata.xml", false)) {
            x.Serialize (myWriter, activePlayer);
        }

When it reaches the StreamWriter line, I get:

A System.UnauthorizedAccessException was thrown.
Access to the path "/private/var/mobile/Containers/Bundle/Application/F6C1DB4B-D2B3-49AF-BA14-D851C7B0B63D/MyGame.app/playerdata.xml" is denied.

Is there something specific that needs to happen to gain access?

Answers

  • JaredMathesJaredMathes CAUniversity

    Hello,

    This is the code that made this work:

    using Foundation;
    var docDir = NSFileManager.DefaultManager.GetUrls (NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User) [0];
    
    XmlSerializer x = new XmlSerializer (activePlayer.GetType ());
    using (StreamWriter myWriter = new StreamWriter (docDir.AbsoluteUrl.RelativePath + "/playerdata.xml", false)) {
        x.Serialize (myWriter, activePlayer);
        }
    
Sign In or Register to comment.