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.

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

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

Same here, would appreciate any news on this subject

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

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