Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by dsrgdeg · Apr 22, 2015 at 01:00 PM · xmlwindows phone 8xmlserializerporting

XML Serialization in Windows phone 8

Hi, I'm using Xml Serialization in my game for saving and loading data.But Windows phone 8 doesn't support it.This is how I've serialized in my Android,IOS and its working fine

 public static void SaveXmlFile(GameDataBase d)
     {
         XmlSerializer serialize = new XmlSerializer (typeof(GameDataBase));
         TextWriter writer = new StringWriter() ;
         serialize.Serialize (writer,d);
         File.WriteAllText (FilePath+"/"+FileName,writer.ToString ());
         
     }
 
 
         public static GameDataBase LoadXmlFile()
     {
 
         string str = File.ReadAllText (FilePath+"/"+FileName);
         XmlSerializer deSerialize = new XmlSerializer (typeof(GameDataBase));
         TextReader reader = new StringReader(str) ;
         GameDataBase gData = (GameDataBase)deSerialize.Deserialize (reader);
 
         return gData;
     }

But when I port it in Windows phone I get the 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(). Error: method System.String > System.Text.Encoding::GetString(System.Byte[]) doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.String _GameSaveLoad::UTF8ByteArrayToString(System.Byte[]).

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Landern · Apr 23, 2015 at 12:33 PM

Windows Phone doesn't allow the usage of System.IO as described in the header of this page. They have their own scheme for Isolated Storage calls for type of data manipulation and storage.

If this is a multiple platform project, you will need to use some compiler directives(UNITY_METRO, UNITY_WP_8_1, UNITY_WINRT, UNITY_WINRT_8_1) to change the storage medium on windows phone.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0
Wiki

Answer by dsrgdeg · Apr 24, 2015 at 02:28 PM

Hi Landern,

I was unable to post this as a comment. My xml Serialization code is working perfectly fine in the editor but when I'm trying to build it on windows phone it is giving me an error

IsolatedStorageException: No ApplicationIdentity available for AppDomain. System.IO.IsolatedStorage.IsolatedStorage.InitStore (IsolatedStorageScope scope, System.Type appEvidenceType) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorage.cs:156) (wrapper remoting-invoke-with-check) System.IO.IsolatedStorage.IsolatedStorage:InitStore (System.IO.IsolatedStorage.IsolatedStorageScope,System.Type) System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs:247) XMLSerialize.Start () (at Assets/Demo/XMLSerialize.cs:37)

Here's a look at my code

 using UnityEngine;
 using System.Collections.Generic;
 using System.Xml.Serialization;
 using System.IO;
 using UnityEngine.UI;
 using System.IO.IsolatedStorage;
 //using Windows.Storage;
 #if NETFX_CORE
 using XmlReader = WinRTLegacy.Xml.XmlReader;
 #else
 using XmlReader = System.Xml.XmlReader;
 #endif
 public class XMLSerialize : MonoBehaviour {
 
 
     TextAsset textFile;
     static AddressDirectory obj;
     public Text showtext;
     // Use this for initialization
     void Start () {
 
 //
 
 
         showtext = GetComponent<Text>();
         //showtext.text = "house:";
          obj  = new AddressDirectory ();
         obj.addressList = new List<Address> ();
         obj.addressList.Add (new Address());
         obj.addressList [0].HouseNo = 50;
 //        SaveXmlFile (obj);
 //        AddressDirectory obj2 = LoadXmlFile ();
 //        print (obj2.addressList [0].HouseNo);
 
 //
     //    var storage = IsolatedStorageFile.GetUserStoreForApplication();
         IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
 //            IsolatedStorageFile.GetStore( IsolatedStorageScope.User 
 //                                         | IsolatedStorageScope.Assembly, null, null );
 
         string[] fileNames = isoStore.GetFileNames( "temp.xml");
 
         print (fileNames.Length);
         foreach ( string file in fileNames )
         {
             if ( file =="temp.xml" )
             {
                 Debug.Log("The file already exists!");
             }
         }
 
 
         IsolatedStorageFileStream oStream = 
             new IsolatedStorageFileStream( "temp.xml", 
                                           FileMode.Create, isoStore );
         
         StreamWriter writer = new StreamWriter( oStream );
                 XmlSerializer serialize = new XmlSerializer (typeof(AddressDirectory));
             
         serialize.Serialize (writer,obj);
         writer.Close();
 
                 
                 AddressDirectory obj2 = LoadXmlFile ();
                 print (obj2.addressList [0].HouseNo);
 //                showtext.text = "house:"+obj2.addressList [0].HouseNo;
     }
     
     public static void SaveXmlFile(AddressDirectory d)
     {
         IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
         IsolatedStorageFileStream stream = null;
 
         stream = new IsolatedStorageFileStream("temp.xml", 
                                                FileMode.OpenOrCreate, 
                                                FileAccess.ReadWrite, 
                                                storage);
         XmlSerializer serializer = new XmlSerializer(typeof (AddressDirectory));
         serializer.Serialize(stream, obj);
 
 
 //        XmlSerializer serialize = new XmlSerializer (typeof(AddressDirectory));
 //        TextWriter writer = new StringWriter() ;
 //        serialize.Serialize (writer,d);
 //        File.WriteAllText (Application.dataPath+"/temp.xml",writer.ToString ());
 //        print (writer+ "   " );
         
         
     }
 
 
     public static AddressDirectory LoadXmlFile()
     {
 //
 //        IsolatedStorageFile isoStore = 
 //            IsolatedStorageFile.GetStore( IsolatedStorageScope.User 
 //                                         | IsolatedStorageScope.Assembly, null, null );
         IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
 
 
         IsolatedStorageFileStream oStream = 
             new IsolatedStorageFileStream( "temp.xml", 
                                           FileMode.Open, isoStore );
         
 
         XmlSerializer serializer = new XmlSerializer(typeof (AddressDirectory));
         //serializer.Serialize(stream, obj);
         AddressDirectory gData = (AddressDirectory)serializer.Deserialize (oStream);
 
         
 //        string str = File.ReadAllText (Application.dataPath+"/temp.xml");
 //        XmlSerializer deSerialize = new XmlSerializer (typeof(AddressDirectory));
 //        TextReader reader = new StringReader(str) ;
 //        AddressDirectory gData = (AddressDirectory)deSerialize.Deserialize (reader);
         //print (str);
         
         return gData;
     }
 }
 
 public class AddressDirectory
 {
     [XmlElement("Address")] 
     public List<Address> addressList = new List<Address>(); 
 
 }
 public class Address
 {
     public int HouseNo ;
     public string StreetName;
     public string City ;
 
     public Address()
     {
         HouseNo = 90;
 
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Windows phone 8.1 after build erros system.io 0 Answers

DataContract serialization not compatible with Unity? 0 Answers

Serialization and XML 1 Answer

Windows phone stack overflow exception 1 Answer

ArgumentException: Path is empty while saving data in an XML 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges