IL2CPP GetInterfaceInvokeDataFromVTableSlowPath vs RaiseExceptionForNotFoundInterface

We were using Unity 2020.1 and getting the following crash on iOS

Crash on Unity 2020.1

[spoiler]

Crashed: com.apple.main-thread
0 UnityFramework 0x106dea00c il2cpp::vm::Class::Init(Il2CppClass*) + 1480 (Class.cpp:1480)
1 UnityFramework 0x106de3040 il2cpp::vm::Type::GetNameInternal(std::1::basic_string<char, std::1::char_traits, std::1::allocator >&, Il2CppType const*, Il2CppTypeNameFormat, bool) + 682 (Type.cpp:682)
2 UnityFramework 0x106de3040 il2cpp::vm::Type::GetNameInternal(std::
1::basic_string, std::1::allocator >&, Il2CppType const*, Il2CppTypeNameFormat, bool) + 682 (Type.cpp:682)
3 UnityFramework 0x106de3464 il2cpp::vm::Type::GetName(Il2CppType const*, Il2CppTypeNameFormat) + 767 (Type.cpp:767)
4 UnityFramework 0x106dc6f10 il2cpp::vm::RaiseExceptionForNotFoundInterface(Il2CppClass const*, Il2CppClass const*, unsigned short) + 1421 (string:1421)
5 UnityFramework 0x106dc6e18 il2cpp::vm::RaiseExceptionForNotFoundInterface(Il2CppClass const*, Il2CppClass const*, unsigned short) + 23 (ClassInlines.cpp:23)
6 UnityFramework 0x107a55844 selector_thread(void*) (.cold.1) + 4423243844
7 UnityFramework 0x107a54e40 selector_thread(void*) (.cold.1) + 4423241280
8 UnityFramework 0x107151430 selector_thread(void*) (.cold.1) + 4413789232
9 UnityFramework 0x1070b6b58 selector_thread(void*) (.cold.1) + 4413156184
10 UnityFramework 0x1071511a8 selector_thread(void*) (.cold.1) + 4413788584
11 UnityFramework 0x107eb63c4 selector_thread(void*) (.cold.1) + 4427834308
12 UnityFramework 0x10822aca0 selector_thread(void*) (.cold.1) + 4431457440
13 UnityFramework 0x10822aca0 selector_thread(void*) (.cold.1) + 4431457440
14 UnityFramework 0x1080ec9fc selector_thread(void*) (.cold.1) + 4430154236
15 UnityFramework 0x10805f7b4 selector_thread(void*) (.cold.1) + 4429576116
16 UnityFramework 0x10805f6e4 selector_thread(void*) (.cold.1) + 4429575908
17 UnityFramework 0x1072110d4 selector_thread(void*) (.cold.1) + 4414574804
18 UnityFramework 0x107148554 selector_thread(void*) (.cold.1) + 4413752660
19 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
20 UnityFramework 0x10759529c selector_thread(void*) (.cold.1) + 4418261660
21 UnityFramework 0x107d90198 selector_thread(void*) (.cold.1) + 4426629528
22 UnityFramework 0x107f49f3c selector_thread(void*) (.cold.1) + 4428439356
23 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
24 UnityFramework 0x107c8f698 selector_thread(void*) (.cold.1) + 4425578136
25 UnityFramework 0x107f46578 selector_thread(void*) (.cold.1) + 4428424568
26 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
27 UnityFramework 0x10759e548 selector_thread(void*) (.cold.1) + 4418299208
28 UnityFramework 0x10710fed4 selector_thread(void*) (.cold.1) + 4413521620
29 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
30 UnityFramework 0x10759e548 selector_thread(void*) (.cold.1) + 4418299208
31 UnityFramework 0x10710fb74 selector_thread(void*) (.cold.1) + 4413520756
32 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
33 UnityFramework 0x10759e548 selector_thread(void*) (.cold.1) + 4418299208
34 UnityFramework 0x107c87110 selector_thread(void*) (.cold.1) + 4425543952
35 UnityFramework 0x107f43900 selector_thread(void*) (.cold.1) + 4428413184
36 UnityFramework 0x1082aad20 selector_thread(void*) (.cold.1) + 4431981856
37 UnityFramework 0x108b8cfd4 selector_thread(void*) (.cold.1) + 4441296852
38 UnityFramework 0x108c874e0 selector_thread(void*) (.cold.1) + 4442322144
39 UnityFramework 0x10593ba24 RuntimeInvoker_TrueVoid_t700C6383A2A510C2CF4DD86DABD5CA9FF70ADAC5(void ()(), MethodInfo const, void*, void*) + 74918 (Il2CppInvokerTable.cpp:74918)
40 UnityFramework 0x106de8310 il2cpp::vm::Runtime::Invoke(MethodInfo const
, void*, void*, Il2CppException) + 573 (Runtime.cpp:573)
41 UnityFramework 0x1065088ac scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr
, bool) + 285 (ScriptingApi_Il2Cpp.cpp:285)
42 UnityFramework 0x106513b20 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 273 (ScriptingInvocation.cpp:273)
43 UnityFramework 0x10640f264 ExecutePlayerLoop(NativePlayerLoopSystem*) + 344 (PlayerLoop.cpp:344)
44 UnityFramework 0x10640f218 ExecutePlayerLoop(NativePlayerLoopSystem*) + 349 (PlayerLoop.cpp:349)
45 UnityFramework 0x10640f470 PlayerLoop() + 428 (PlayerLoop.cpp:428)
46 UnityFramework 0x1068f4bac UnityPlayerLoopImpl(bool) + 296 (LibEntryPoint.mm:296)
47 UnityFramework 0x10581b010 UnityRepaint + 284 (UnityAppController+Rendering.mm:284)
48 UnityFramework 0x10581aeec -[UnityAppController(Rendering) repaintDisplayLink] + 72 (UnityAppController+Rendering.mm:72)
49 QuartzCore 0x19e735fac CA::smile:isplay::smile:isplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 516
50 IOKit 0x198cc0650 IODispatchCalloutFromCFMessage + 480
51 CoreFoundation 0x197cc6b34 __CFMachPortPerform + 172
52 CoreFoundation 0x197cf0174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 56
53 CoreFoundation 0x197cef880 __CFRunLoopDoSource1 + 444
54 CoreFoundation 0x197cea634 __CFRunLoopRun + 1888
55 CoreFoundation 0x197ce9ba8 CFRunLoopRunSpecific + 424
56 GraphicsServices 0x1a1e59344 GSEventRunModal + 160
57 UIKitCore 0x19be253e4 UIApplicationMain + 1932
58 UnityFramework 0x1058199ac -[UnityFramework runUIApplicationMainWithArgc:argv:] + 96 (main.mm:96)
59 narcosfactory 0x1041ffe1c main + 28 (main.mm:28)
60 libdyld.dylib 0x197b718f0 start + 4

[/spoiler]

We downgraded to Unity LTS 2019.4.8 and added Exception handling on worker threads, Now the crash has changed

Crash on Unity 2019.4.8

[spoiler]

Crashed: com.apple.main-thread
0 UnityFramework 0x1065042c0 il2cpp::vm::Class::Init(Il2CppClass*) + 1480 (Class.cpp:1480)
1 UnityFramework 0x1064fd35c il2cpp::vm::Type::GetNameInternal(std::1::basic_string<char, std::1::char_traits, std::1::allocator >&, Il2CppType const*, Il2CppTypeNameFormat, bool) + 682 (Type.cpp:682)
2 UnityFramework 0x1064fd35c il2cpp::vm::Type::GetNameInternal(std::
1::basic_string, std::1::allocator >&, Il2CppType const*, Il2CppTypeNameFormat, bool) + 682 (Type.cpp:682)
3 UnityFramework 0x1064fd7e8 il2cpp::vm::Type::GetName(Il2CppType const*, Il2CppTypeNameFormat) + 767 (Type.cpp:767)
4 UnityFramework 0x1064e0dfc il2cpp::vm::ClassInlines::GetInterfaceInvokeDataFromVTableSlowPath(Il2CppObject*, Il2CppClass const*, unsigned int) + 1255 (string:1255)
5 UnityFramework 0x1070ac94c FBLPromiseCombineValuesAndErrors.cold.1 + 4373252428
6 UnityFramework 0x1070abf48 FBLPromiseCombineValuesAndErrors.cold.1 + 4373249864
7 UnityFramework 0x106913188 FBLPromiseCombineValuesAndErrors.cold.1 + 4365283720
8 UnityFramework 0x106912dbc FBLPromiseCombineValuesAndErrors.cold.1 + 4365282748
9 UnityFramework 0x106912f00 FBLPromiseCombineValuesAndErrors.cold.1 + 4365283072
10 UnityFramework 0x10735d264 FBLPromiseCombineValuesAndErrors.cold.1 + 4376072804
11 UnityFramework 0x106dbff00 FBLPromiseCombineValuesAndErrors.cold.1 + 4370185984
12 UnityFramework 0x106dbff00 FBLPromiseCombineValuesAndErrors.cold.1 + 4370185984
13 UnityFramework 0x10789fe48 FBLPromiseCombineValuesAndErrors.cold.1 + 4381589064
14 UnityFramework 0x106e487b0 FBLPromiseCombineValuesAndErrors.cold.1 + 4370745264
15 UnityFramework 0x106e486e0 FBLPromiseCombineValuesAndErrors.cold.1 + 4370745056
16 UnityFramework 0x1069115fc FBLPromiseCombineValuesAndErrors.cold.1 + 4365276668
17 UnityFramework 0x106911f28 FBLPromiseCombineValuesAndErrors.cold.1 + 4365279016
18 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
19 UnityFramework 0x10777ed28 FBLPromiseCombineValuesAndErrors.cold.1 + 4380405032
20 UnityFramework 0x107757a1c FBLPromiseCombineValuesAndErrors.cold.1 + 4380244508
21 UnityFramework 0x10772b244 FBLPromiseCombineValuesAndErrors.cold.1 + 4380062276
22 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
23 UnityFramework 0x1077616bc FBLPromiseCombineValuesAndErrors.cold.1 + 4380284604
24 UnityFramework 0x10772da1c FBLPromiseCombineValuesAndErrors.cold.1 + 4380072476
25 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
26 UnityFramework 0x10777a57c FBLPromiseCombineValuesAndErrors.cold.1 + 4380386684
27 UnityFramework 0x10690dc60 FBLPromiseCombineValuesAndErrors.cold.1 + 4365261920
28 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
29 UnityFramework 0x10777a57c FBLPromiseCombineValuesAndErrors.cold.1 + 4380386684
30 UnityFramework 0x10690d908 FBLPromiseCombineValuesAndErrors.cold.1 + 4365261064
31 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
32 UnityFramework 0x10777a57c FBLPromiseCombineValuesAndErrors.cold.1 + 4380386684
33 UnityFramework 0x10775659c FBLPromiseCombineValuesAndErrors.cold.1 + 4380239260
34 UnityFramework 0x10772ad2c FBLPromiseCombineValuesAndErrors.cold.1 + 4380060972
35 UnityFramework 0x107a4d3d4 FBLPromiseCombineValuesAndErrors.cold.1 + 4383347668
36 UnityFramework 0x1081e6c5c FBLPromiseCombineValuesAndErrors.cold.1 + 4391316572
37 UnityFramework 0x1082c52d8 FBLPromiseCombineValuesAndErrors.cold.1 + 4392227544
38 UnityFramework 0x10507468c RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017(void ()(), MethodInfo const, void*, void*) + 73354 (Il2CppInvokerTable.cpp:73354)
39 UnityFramework 0x10650257c il2cpp::vm::Runtime::Invoke(MethodInfo const
, void*, void*, Il2CppException) + 553 (Runtime.cpp:553)
40 UnityFramework 0x105d02734 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr
, bool) + 285 (ScriptingApi_Il2Cpp.cpp:285)
41 UnityFramework 0x105d0dd94 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 273 (ScriptingInvocation.cpp:273)
42 UnityFramework 0x105c1ea34 ExecutePlayerLoop(NativePlayerLoopSystem*) + 344 (PlayerLoop.cpp:344)
43 UnityFramework 0x105c1e9e8 ExecutePlayerLoop(NativePlayerLoopSystem*) + 349 (PlayerLoop.cpp:349)
44 UnityFramework 0x105c1ec40 PlayerLoop() + 428 (PlayerLoop.cpp:428)
45 UnityFramework 0x10601a2b4 UnityPlayerLoopImpl(bool) + 296 (LibEntryPoint.mm:296)
46 UnityFramework 0x104f568d4 UnityRepaint + 285 (UnityAppController+Rendering.mm:285)
47 UnityFramework 0x104f567b0 -[UnityAppController(Rendering) repaintDisplayLink] + 72 (UnityAppController+Rendering.mm:72)
48 QuartzCore 0x187e3dd6c CA::smile:isplay::smile:isplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 512
49 QuartzCore 0x187f0d5fc display_timer_callback(
CFMachPort*, void*, long, void*) + 268
50 CoreFoundation 0x181282c68 CFMachPortPerform + 176
51 CoreFoundation 0x1812ad3f0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 60
52 CoreFoundation 0x1812aca9c __CFRunLoopDoSource1 + 448
53 CoreFoundation 0x1812a7630 __CFRunLoopRun + 1856
54 CoreFoundation 0x1812a6bc8 CFRunLoopRunSpecific + 480
55 GraphicsServices 0x18b68f5cc GSEventRunModal + 164
56 UIKitCore 0x185459744 UIApplicationMain + 1936
57 UnityFramework 0x104f55274 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 96 (main.mm:96)
58 narcosfactory 0x104bebe1c main + 28 (main.mm:28)
59 libdyld.dylib 0x181123384 start + 4

[/spoiler]

We've also seen a Crash on the Previous Version which is similar If it helps to sort out the problem. but doesn't show up on new version

Similar Crash with different StackTrace on Unity 2020.1

[spoiler]

Crashed: com.apple.main-thread
0 UnityFramework 0x1075ea00c il2cpp::vm::Class::Init(Il2CppClass*) + 1480 (Class.cpp:1480)
1 UnityFramework 0x1075eac48 il2cpp::vm::Class::IsAssignableFrom(Il2CppClass*, Il2CppClass*) + 1559 (Class.cpp:1559)
2 UnityFramework 0x1075eac48 il2cpp::vm::Class::IsAssignableFrom(Il2CppClass*, Il2CppClass*) + 1559 (Class.cpp:1559)
3 UnityFramework 0x1075c9ab8 il2cpp::vm::Object::IsInst(Il2CppObject*, Il2CppClass*) + 245 (Object.cpp:245)
4 UnityFramework 0x108e2f764 selector_thread(void*) (.cold.1) + 4347082596
5 UnityFramework 0x108e31794 selector_thread(void*) (.cold.1) + 4347090836
6 UnityFramework 0x108e2fb04 selector_thread(void*) (.cold.1) + 4347083524
7 UnityFramework 0x108e31794 selector_thread(void*) (.cold.1) + 4347090836
8 UnityFramework 0x108e2fb04 selector_thread(void*) (.cold.1) + 4347083524
9 UnityFramework 0x108e2fd08 selector_thread(void*) (.cold.1) + 4347084040
10 UnityFramework 0x108e2f62c selector_thread(void*) (.cold.1) + 4347082284
11 UnityFramework 0x107b7d968 selector_thread(void*) (.cold.1) + 4327479656
12 UnityFramework 0x107b7d5b0 selector_thread(void*) (.cold.1) + 4327478704
13 UnityFramework 0x108d64a68 selector_thread(void*) (.cold.1) + 4346251880
14 UnityFramework 0x1087df21c selector_thread(void*) (.cold.1) + 4340462108
15 UnityFramework 0x107b9391c selector_thread(void*) (.cold.1) + 4327569692
16 UnityFramework 0x107b9357c selector_thread(void*) (.cold.1) + 4327568764
17 UnityFramework 0x1078c03e8 selector_thread(void*) (.cold.1) + 4324606952
18 UnityFramework 0x1079590e8 selector_thread(void*) (.cold.1) + 4325232872
19 UnityFramework 0x1078bf488 selector_thread(void*) (.cold.1) + 4324603016
20 UnityFramework 0x10793975c selector_thread(void*) (.cold.1) + 4325103452
21 UnityFramework 0x108aaad20 selector_thread(void*) (.cold.1) + 4343393568
22 UnityFramework 0x107d9e548 selector_thread(void*) (.cold.1) + 4329710920
23 UnityFramework 0x107952cd8 selector_thread(void*) (.cold.1) + 4325207256
24 UnityFramework 0x108aaad20 selector_thread(void*) (.cold.1) + 4343393568
25 UnityFramework 0x108b412dc selector_thread(void*) (.cold.1) + 4344009436
26 UnityFramework 0x1094813b4 selector_thread(void*) (.cold.1) + 4353708980
27 UnityFramework 0x1094812fc selector_thread(void*) (.cold.1) + 4353708796
28 UnityFramework 0x10613b514 RuntimeInvoker_FalseVoid_t700C6383A2A510C2CF4DD86DABD5CA9FF70ADAC5(void ()(), MethodInfo const, void*, void*) + 74778 (Il2CppInvokerTable.cpp:74778)
29 UnityFramework 0x1075e8310 il2cpp::vm::Runtime::Invoke(MethodInfo const
, void*, void*, Il2CppException) + 573 (Runtime.cpp:573)
30 UnityFramework 0x106d088ac scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr
, bool) + 285 (ScriptingApi_Il2Cpp.cpp:285)
31 UnityFramework 0x106d13b20 ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 273 (ScriptingInvocation.cpp:273)
32 UnityFramework 0x10684767c Scripting::UnityEngine::UnitySynchronizationContextProxy::ExecuteTasks(ScriptingExceptionPtr*) + 2211 (CoreScriptingClasses.cpp:2211)
33 UnityFramework 0x106c0f1e4 ExecutePlayerLoop(NativePlayerLoopSystem*) + 331 (PlayerLoop.cpp:331)
34 UnityFramework 0x106c0f218 ExecutePlayerLoop(NativePlayerLoopSystem*) + 349 (PlayerLoop.cpp:349)
35 UnityFramework 0x106c0f470 PlayerLoop() + 428 (PlayerLoop.cpp:428)
36 UnityFramework 0x1070f4bac UnityPlayerLoopImpl(bool) + 296 (LibEntryPoint.mm:296)
37 UnityFramework 0x10601b010 UnityRepaint + 284 (UnityAppController+Rendering.mm:284)
38 UnityFramework 0x10601aeec -[UnityAppController(Rendering) repaintDisplayLink] + 72 (UnityAppController+Rendering.mm:72)
39 QuartzCore 0x1a1129fac CA::smile:isplay::smile:isplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 516
40 IOKit 0x19b6b4650 IODispatchCalloutFromCFMessage + 480
41 CoreFoundation 0x19a6bab34 CFMachPortPerform + 172
42 CoreFoundation 0x19a6e4174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
+ 56
43 CoreFoundation 0x19a6e3880 __CFRunLoopDoSource1 + 444
44 CoreFoundation 0x19a6de634 __CFRunLoopRun + 1888
45 CoreFoundation 0x19a6ddba8 CFRunLoopRunSpecific + 424
46 GraphicsServices 0x1a484d344 GSEventRunModal + 160
47 UIKitCore 0x19e8193e4 UIApplicationMain + 1932
48 UnityFramework 0x1060199ac -[UnityFramework runUIApplicationMainWithArgc:argv:] + 96 (main.mm:96)
49 narcosfactory 0x10471be1c main + 28 (main.mm:28)
50 libdyld.dylib 0x19a5658f0 start + 4

[/spoiler]

My observations by looking at the logs
- FBLPromiseCombineValuesAndErrors is replaced with selector_thread
- Now the exception is being caught So new logs don't RaiseExceptionForNotFoundInterface

Questions?
- il2cpp::vm::Type::GetName is it getting called somewhere from C# code (example: typeof(baseClass).Name) and is this going to a problem using this if we wanted to get the Actual type name?

My thoughts were (I could be wrong) We're using JSON.Net and we are using different threads for Serialization and Deserialization, If an exception is thrown in that thread we add it to a thread safe list where exception get cached and on Update method, we take the first item and we post the logs with Exception Name using [ Exception.GetType().Name ] and Exception.StackTrace which I think is causing issues with IL2CPP,

These logs are from firebase, We're not able to reproduce this on our end

Thanks in advance

My guess is that these stack frames are reported incorrectly by firebase. These are in instead likely stack frames in generated managed code. It looks like the symbols files generated by the Xcode build are not accessible to firebase, so it cannot look up the proper symbols. I'm not familiar enough with firebase to know how to give it the symbols, but if you can do that, then it should be much easier to see what is happening.

In general, this should be safe to call from pretty much anywhere in C# code.

My initial guess is that the managed code stripper is removing some code for types that are only used via serialization from JSON, and the crash manifests itself due to that missing information. But I'm not really sure from this information alone.

Thanks for the reply, I've investigated the issue more here are few more information that I found out

FBLPromiseCombineValuesAndErrors is a Firebase Pod Dependencies So it seems like this is a Firebase Issue, I don't see anything related to our code in the stack trace, So maybe the firebase is caching our logs (Firebase.Log) than sending them to in a different loop, We don't see this crash being posted to Unity Cloud Diagnostics Tool this is weird,

I've opened an issue on Firebase https://github.com/firebase/quickstart-unity/issues/781