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 /
avatar image
3
Question by ikeo · Sep 01, 2010 at 11:07 AM · iphoneserializationxml

How do I use deserialize XML with Unity Pro iPhone.

I am attempting to use the XML serializer in System.XML.Serialization. My XML file deserializes fine on the mac, and fails on the iPhone with the following:

Attempting to JIT compile method '(wrapper delegate-invoke) System.Reflection.MonoProperty/Getter`2:invoke_string_this__fx_common_color_or_texture_typeColor (goBuild.goBIM.fx_common_color_or_texture_typeColor)' while running with --aot-only.

Apparently it's trying to JIT compile methods in my XML, and the only [suggested work-around][1] from Mono is to call each method that I will eventually need prior to deserialization in order to force inclusion in AOT. This is unreasonable for a number of reasons, not the least of which is that I don't know exactly what methods I'll need.

Does anyone know how to get this to work?

I'm using Unity Pro iPhone with stripping disabled targeting .NET 2.1.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mindlube · Feb 23, 2011 at 11:29 PM

Hi were you able to solve this? I am getting the same problem, involving a 3rd party Serialization library (protobuf-net)

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

Answer by poncho · Mar 15, 2011 at 02:59 PM

for this one you need

XmlSerializer serializer = new XmlSerializer(typeof(YourClass)); YourClass yourClassVariable = (YourClass)serializer.Deserialize(thestreamofyourfile);

with this the varialbe "yourClassVariable" will have all the xml info there

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

Answer by SeikoTheWiz · Aug 22, 2012 at 10:18 AM

Same here, would appreciate any news on this subject

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

Answer by SSauerGFG · Oct 10, 2012 at 09:39 PM

EDIT: Hey all, I found a way to deserialize an xml (for reading) while still keeping the files organized in unity without going through any odd steps

Here's an example of how it worked in the editor (minus all debugging and error checking):

 public MyType DeserializeFromPath(string filePath)
 {    
     // Set up serializer of the correct type & grab file from the given path
     XmlSerializer mySerializer = new XmlSerializer(typeof(MyType));
      TextReader textReader = new StreamReader(@xmlPath);
     //Deserialize file to return, closing my textReader before the return call
     MyType ret =  (MyType)mySerializer.Deserialize(textReader);
     textReader.Close()
     return ret;
 }

And here's my example (minus all debugging and error checking) of how it works on the iPad build:

 void Start()
 {
     TextAsset textAsset = Resources.Load("myXML") as TextAsset;
     MyType myType = DeserializeFromString(textAsset.Text);
 }
 
 
 public MyType DeserializeFromString(string fileContents)
 {    
     //Set up serializer of the correct type & place text into a string reader
     XmlSerializer mySerializer = new XmlSerializer(typeof(MyType));
      StringReader strReader = new StringReader(fileContents);
     //Use the string reader to create an object that can be deserialized
     XmlTextReader xmlFromText = new XmlTextReader(strReader);
     //Deserialize file to return, closing my Readers before returning 
     MyType ret =  (MyType)mySerializer.Deserialize(xmlFromText);
     strReader.Close();
     xmlFromText.Close();
     return ret;
 }

In the latter example, I use a basic unity Resources.Load call to get the xml file as a TextAsset so that it may be used as a block of text (string) rather than using a file path. I then use that text to initialize an object (XmlTextReader) that can be (de)serialized. I'm not too sure if I used too many steps or if this is the only/right way to do this, but I do know it works. Feel free to comment with any questions/flaws you'd like to point out. Hope I helped! :)

Original Post:

Hey there!

I am having the exact same problem. Using the Deserialize function I Use -> Application.dataPath + "/Resources/_XML/sfx.xml" <- as my file path. But this will not work on the iOS device the build is intended for. I have found a way to manually place a folder with my .xml file directly into the build folder so that I can access it directly. This is still a huge pain in my behind as far as updates and other co-workers possibly deleting or even use the file and my system. I guess in summary, I would like to know how to use the same style of loading that worked with the 'in editor' version that still works on iOS. It doesn't have to be the exact same code for both cases, just something that would allows us to keep the files within the Unity Editor and easily accessible by anyone with our Unity build.

Thanks for any help in advanced! :)

Comment
Add comment · Show 1 · 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 SSauerGFG · Oct 11, 2012 at 05:04 PM 0
Share

http://answers.unity3d.com/questions/132753/how-do-i-read-xml-on-iphone.html

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

PlayerPrefs v. XML File for Saving Data? 1 Answer

Mapping between classes for serialization 2 Answers

Does PlayerPref fits to save data profile on IPhone game 1 Answer

How to save my serialized levels ? 1 Answer

Problem with XML Serialization in Android (XMLException) 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