x


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.

more ▼

asked Sep 01 '10 at 11:07 AM

ikeo gravatar image

ikeo
136 9 11 18

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Same here, would appreciate any news on this subject

more ▼

answered Aug 22 '12 at 10:18 AM

SeikoTheWiz gravatar image

SeikoTheWiz
61 3 4 5

(comments are locked)
10|3000 characters needed characters left

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! :)

more ▼

answered Oct 10 '12 at 09:39 PM

SSauerGFG gravatar image

SSauerGFG
16 2 4

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Mar 15 '11 at 02:59 PM

poncho gravatar image

poncho
932 2 3 14

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Feb 23 '11 at 11:29 PM

mindlube gravatar image

mindlube
238 2 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1999
x255
x178

asked: Sep 01 '10 at 11:07 AM

Seen: 2008 times

Last Updated: Oct 11 '12 at 05:04 PM