XML reading Problem while porting android project to windows phone 8

I get this error

Error building Player: Exception: Error: method System.Void System.IO.File::WriteAllText(System.String,System.String)
doesn’t exist in target framework. It
is referenced from Assembly-CSharp.dll
at System.Void
XMLSerialize::SaveXmlFile(AddressDirectory).
Error: method System.String System.IO.File::ReadAllText(System.String)
doesn’t exist in target framework. It
is referenced from Assembly-CSharp.dll
at AddressDirectory
XMLSerialize::LoadXmlFile(). Error:
method System.Void System.IO.File::WriteAllText(System.String,System.String)
doesn’t exist in target framework. It
is referenced from Assembly-CSharp.dll
at System.Void
XMLSerialization::SaveXmlFile(GameDataBase).
Error: method System.String System.IO.File::ReadAllText(System.String)
doesn’t exist in target framework. It
is referenced from Assembly-CSharp.dll
at GameDataBase
XMLSerialization::LoadXmlFile().

I added this code in the xml.cs I was using but it didn’t help

#if NETFX_CORE using XmlReader = WinRTLegacy.Xml.XmlReader;
#else using XmlReader = System.Xml.XmlReader;
#endif

Please read the documentation:

http://docs.unity3d.com/Manual/wp8-missingtypes.html

You’ll learn that WP8 lacks some .NET APIs that you are familiar with. For example, the error message:

System.IO.File::WriteAllText(System.String,System.String) doesn't exist in target framework

tells you that an API you are trying to use doesn’t exist.

This one works for me.

  • ReadAllTex:

    string temp=File.ReadAllText(Application.persistentDataPath+“/”+savedImageName+“.txt”);

Change it as =>

string temp = string.Empty;
		byte[] data = UnityEngine.Windows.File.ReadAllBytes (Application.persistentDataPath+"/"+savedImageName+".txt");
		temp = System.Text.Encoding.UTF8.GetString (data, 0, data.Length);
  • WriteAllText:

If used this

File.WriteAllText(Application.persistentDataPath+"/"+imageName+".txt",temp);

Change it as =>

UnityEngine.Windows.File.WriteAllBytes (Application.persistentDataPath + "/" + imageName + ".txt", System.Text.Encoding.UTF8.GetBytes (temp));