Saving/Loading data to Windows Phone 8

I have successfully created a class which handles saving and loading a custom class for the vast majority of devices available (thank you to this great live training session).

BinaryFormatter binaryFormatter = new BinaryFormatter();
FileStream file = null;

// Check whether a player file already exists
if(File.Exists(Application.persistentDataPath + k_PlayerInfoFileName))
{
	file = File.Open(Application.persistentDataPath + k_PlayerInfoFileName, FileMode.Open);
}
else
{
	file = File.Create(Application.persistentDataPath + k_PlayerInfoFileName);
}

Player_Info data = new Player_Info();
data.m_CurrentLevel = m_CurrentLevel;
data.m_UnlockedLevel = m_UnlockedLevel; 
data.m_LevelScores = m_LevelScores;

binaryFormatter.Serialize(file, data);
file.Close();

However, the process I’ve used (as demonstrated above) doesn’t work with a Windows Phone 8. Is there an alternative class or method I can use which saves a custom class specifically for targeting WP8?

Binary Serialisation is not supported on Windows Phone (the supporting classes are missing on there)

Use XMLSerialiser or other serialiser instead.

There is a nice JSON serialiser on the asset store which is pretty good.

Are you using System.Io, if you are, it’s not available to Windows Store Apps and Windows Phone 8 simply because this API doesn’t exist in these platforms. It was replaced by the Windows.Storage API, and that’s what you have to use for these platforms (WSA & WP8).

I’m getting stuck to this propblem too, if you find out some way, please tell me!

Windows phone is a bit funny with serialisation, you can’t use System.IO for most things. You can either try using UnityEngine.Windows.File API or WinRTLegacy. I tried the former and it seems to work.

Found all the information for this On this Page.