Hi, I am trying to save data to the iPhone and get the following error message from the console in xcode:
This mono runtime was configured with --enable-minimal=reflection_emit, so System.Reflection.Emit is not supported.
this is triggered by:
path = Application.dataPath.Substring(0, Application.dataPath.Length - 4) + "Documents";
Stream fileStream = File.Open(path + "/" + filename, FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, obj);
fileStream.Close();
The error is triggered by the formatter.Serialize(fileStream.obj) line
Is there a way to save serialized data to the iphone (I have no idea what the error message is telling me)
It all works fine on the mac (no issues at all via remote)
thanks
iPhone Basic/Advance doesn’t include all the classes that are in .net 1.1.
This would add a lot of overhead(file size) to your project when your are not even using the namespaces.
System.Reflection.Emit was removed from the deployment using that switch:
–enable-minimal=reflection_emit
So the support for anything in the Reflection.Emit namespace(methods, classes, properties, etc) goes out the door.
Is this one of the using(includes) in your source?
what is in obj?
The Emit Namespace does some really advanced stuff.
Hey WM,
Obj is an array which is populated with a custom type.
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
Am now looking at another solution as I doubt if this one will be fixed (report submitted).
thx
Hi,
BinaryFormatter is not supported on Unity iPhone, because internally it uses Reflection.Emit.
Thx for the reply mantasp
any workaround for serializing stuff in Unity
(I have 1.7 basic)
i’m getting the same crash.
I just had the same error about System.Reflection.Emit, and it was caused by the following line (which I’m using in a cross platform project, to make sure floating point values are saved the same way on any locale):
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
I solved it by making sure it isn’t compiled in Unity iPhone:
#if !UNITY_IPHONE
// force locale to be en-US so conversions between float and string are always done the same way
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
#endif
and is there anything to do in unity iphone to serialize stuff with floats?
I didn’t test it, but I don’t think there are similar issues on the iPhone.
Just in case anyone stumbles on this thead, the following code fixed this issue for me:
#if UNITY_IPHONE
// Forces a different code path in the BinaryFormatter that doesn't rely on run-time code generation (which would break on iOS).
System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
#endif
Found from here.
1 Like