Author Topic: GetEnUsCulture error on mono  (Read 2722 times)

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
GetEnUsCulture error on mono
« on: November 28, 2016, 02:06:38 AM »
When I compile ios and choose backend as mono then I am getting the following error.

ExecutionEngineException: Attempting to JIT compile method 'CultureInfo__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 System.Threading.Thread.set_CurrentCulture (System.Globalization.CultureInfo value) [0x00000] in <filename unknown>:0
  at TNet.Tools.GetEnUsCulture () [0x00000] in <filename unknown>:0
  at TNet.Tools..cctor () [0x00000] in <filename unknown>:0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for TNet.Tools

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #1 on: November 28, 2016, 02:21:57 AM »
I changed the function to this
return new System.Globalization.CultureInfo("en-US");
and that fixed it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #2 on: November 28, 2016, 11:12:57 AM »
Which function did you change?

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #3 on: November 28, 2016, 11:38:53 PM »
TNTools

static public System.Globalization.CultureInfo englishUSCulture = GetEnUsCulture();

   static System.Globalization.CultureInfo GetEnUsCulture ()
   {
      return new System.Globalization.CultureInfo("en-US");
      //var thread = Thread.CurrentThread;
      //var culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
      //culture.NumberFormat.CurrencyDecimalSeparator = ".";
      //if (thread != null) thread.CurrentCulture = culture;
      //return culture;
   }

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #4 on: November 28, 2016, 11:48:54 PM »
I also added the following to an Awake statement based on a forum post and have not traced the true fix yet

Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #5 on: November 29, 2016, 01:43:07 PM »
So what's failing on iOS exactly? Is it the CreateSpecificCulture? I assign the thread's culture in that same function that you commented out. TNet has many threads, so each would need this set individually which is why I had it done in this function.

Does this work?
  1.         static System.Globalization.CultureInfo GetEnUsCulture ()
  2.         {
  3.                 var thread = Thread.CurrentThread;
  4.                 var culture = new System.Globalization.CultureInfo("en-US");
  5.                
  6.                 if (thread != null)
  7.                 {
  8.                         thread.CurrentCulture = culture;
  9.                         thread.CurrentUICulture = culture;
  10.                 }
  11.                 return culture;
  12.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #6 on: November 29, 2016, 02:10:47 PM »
Looking some more at the code, the en-US culture is only needed for float parsing, and TNet forces it when parsing floats -- so setting it for the entire threads is likely unnecessary.

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: GetEnUsCulture error on mono
« Reply #7 on: December 01, 2016, 11:08:17 PM »
I commented this out and it still worked
//Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
//System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

I tried your function but that did not work. same error.

so far this is only thing working for mono backend for ios
      return new System.Globalization.CultureInfo("en-US");

I only use mono on ios because it build so much faster and I use a debug tool to serialize build to editor,

il2cpp works with original function