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
0
Question by CazicThule · Jul 18, 2012 at 10:18 PM · iphoneserializationsavereflection

Serialization reflection ExecutionEngineException on iPhone

I'm attempting to save my game with serialization like so:

 worldData data = m_WorldData;
 Stream stream = File.Open(GetiPhoneDocumentsPath()+"/MySavedGame.game", FileMode.Create);
 BinaryFormatter bformatter = new BinaryFormatter();
 bformatter.Binder = new VersionDeserializationBinder(); 
 Debug.Log ("Writing Information");
 bformatter.Serialize(stream, data);
 stream.Close();

This works fine on the PC, but on iPhone it gives the following reflection error. Does anyone have any idea what the problem may be?

 ExecutionEngineException: Attempting to JIT compile method 'List`1__TypeMetadata:.ctor ()' while running with --aot-only.

 at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
 Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0 
   at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0 
   at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.CreateMemberTypeMetadata (System.Type type) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData (System.Object obj, System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata, System.Object& data) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObject (System.IO.BinaryWriter writer, Int64 id, System.Object obj) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance (System.IO.BinaryWriter writer, System.Object obj, Boolean isValueObject) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects (System.IO.BinaryWriter writer) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph (System.IO.BinaryWriter writer, System.Object obj, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in <filename unknown>:0 
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) [0x00000] in <filename unknown>:0 
   at WorldGameObject.Save () [0x00000] in <filename unknown>:0 
   at HUD.OnGUI () [0x00000] in <filename unknown>:0 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Baerrach · Jun 08, 2013 at 11:53 PM

Please see The game crashes with the error message "ExecutionEngineException: Attempting to JIT compile method 'SometType`1:.ctor ()' while running with --aot-only."

I've got the same problem and from google searches am finding that List and Queue types might need JIT in order to work correctly.

On the iPhone JIT is not allowed.

I have yet to find the correct way to resolve this.

Some pages suggest using XmlSerialization instead. However Stackoverflow What are the differences between xml and binary formatter shows that XML doesnt handle graphs of objects that reference each other, nor private fields. So I'm sticking with BinaryFormatter.

My current workaround is to mark the class containing these generic collections with [Serializable] and implementing this interface ISerializable which requires these two methods (as per Serialization (C# and Visual Basic))

I then unroll the collection types manually:

     public void GetObjectData (SerializationInfo info, StreamingContext context)
     {
             Object[] queueContents = aQueue.ToArray();
             info.AddValue ("aQueue.count", queueContents.Count());
             for (int i=0; i < queueContents.Count(); i++) {
                     info.AddValue ("aQueue[" + i + "]", queueContents [i]);
             }
     }

     // The special constructor is used to deserialize values. 
     public MyClassname (SerializationInfo info, StreamingContext context)
     {
             int aQueueCount = info.GetInt32 ("aQueue.count");
             for (int i=0; i < aQueueCount; i++) {
                     ActualClass obj = (ActualClass)info.GetValue ("aQueue[" + i + "]", typeof(ActualClass));
                     aQueue.Enqueue(obj);
             }
     }

BinaryFormatter includes type meta data in the output stream it knows the real subtypes and can create the right types of objects for you without you having to do any more work.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to save a procedurally-generated mesh on the client machine? 1 Answer

Saving serialized data for iOS 0 Answers

Is it possible to serialize and store custom structs on the iPhone in scriptableObjects? 2 Answers

Serializer deletes saved info on game restart 1 Answer

Saving game question. 1 Answer


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