Calling ServiceStack.Text.JsConfig.RegisterTypeFor

2019-08-13 16:33发布

问题:

I've been trying to use ServiceStack.Text.JsConfig.RegisterTypeForAot(); in an method that is not used at runtime to cure my AOT issues but have run into other weird issues when I have too many calls to it. I've got 10 calls to various types including classes, structs and enums. When I have 9 calls everything works fine, I've shuffled some of the types around so I'm pretty sure it is the number. When I have 10 calls I get ...

Stacktrace:

  at System.MonoType.ToString () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/MonoType.cs:636
  at System.Exception.get_ClassName () [0x0000b] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Exception.cs:141
  at System.Exception.ToString () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Exception.cs:286
  at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
  at System.Type.Equals (System.Type) [0x00020] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Type.cs:471
  at System.Type.IsAssignableFrom (System.Type) [0x00008] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Type.cs:863
  at System.Collections.Generic.EqualityComparer`1<intptr>..cctor () [0x00029] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs:42
  at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
  at System.Collections.Generic.Dictionary`2<intptr, System.WeakReference>.Init (int,System.Collections.Generic.IEqualityComparer`1<intptr>) [0x00012] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:265
  at System.Collections.Generic.Dictionary`2<intptr, System.WeakReference>..ctor () [0x00006] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:223
  at MonoTouch.ObjCRuntime.Runtime..cctor () <IL 0x00000, 0x0002b>
  at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

    0   TouchContainer                      0x028dbda5 mono_handle_native_sigsegv + 244
    1   TouchContainer                      0x028a3cfd mono_sigsegv_signal_handler + 172
    2   libsystem_c.dylib                   0x320e8e93 _sigtramp + 42
    3   TouchContainer                      0x0093aa25 ServiceStack_Text_Common_JsWriter_WriteEnumFlags_System_IO_TextWriter_object + 381

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

TouchContainer being the name of the app.

This seems to be happening so early in the run of the app that it must be a bug in the AOT or something that is emitting bad code.

Does anyone have any ideas? Shall I log a ticket with Xamarin on this? It looks like it could be tricky to work up a small repro project...

回答1:

Rolf suggested (in the bug comments) adding -f to the monotouch arguments. This seems to have fixed it.