ArrayTypeMismatchException thrown when initializing an AggregateException

Viewed 125

In my Xamarin.Forms app, I am seeing instances where a background thread crashes, the app attempts to construct an AggregateException to send to TaskScheduler.UnobservedTaskException, but throws an ArrayTypeMismatchException in the initializer for the AggregateException. This seems to only be happening on iOS.

This is being reported in AppCenter very frequently, and is currently my top crash. However, I've been unable to repro. When I explicitly throw exceptions on background threads, it is able to build the AggregateExceptions without issue. Any help would be much appreciated.

Here is the relevant stack trace:

Exception Codes: #0 at 0x19083ad88
Crashed Thread:  6

Application Specific Information:
*** Terminating app due to uncaught exception 'SIGABRT', reason: 'Attempted to access an element as a type incompatible with the array.'

Xamarin Exception Stack:
System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
  at (wrapper stelemref) System.Object.virt_stelemref_class_small_idepth(intptr,object)
  at System.AggregateException..ctor (System.String message, System.Collections.Generic.IList`1[T] innerExceptionInfos) <0x1006d41ec + 0x00127> in <7df0b59b3ac34c319d58e821ad54104a#eba08df608efe53844894d720d943b17>:0
  at System.AggregateException..ctor (System.String message, System.Collections.Generic.IEnumerable`1[T] innerExceptionInfos) <0x1006d40e4 + 0x000f3> in <7df0b59b3ac34c319d58e821ad54104a#eba08df608efe53844894d720d943b17>:0
  at System.Threading.Tasks.TaskExceptionHolder.Finalize () <0x1007820c4 + 0x000a7> in <7df0b59b3ac34c319d58e821ad54104a#eba08df608efe53844894d720d943b17>:0

Thread 6 Crashed:
0   libsystem_kernel.dylib               0x000000019083ad88 __pthread_kill + 8
1   libsystem_c.dylib                    0x00000001906a6934 abort + 96
2   My.Project.iOS                        0x000000010326e0f8 xamarin_unhandled_exception_handler.cold.1 + 32
3   My.Project.iOS                        0x000000010322557c xamarin_unhandled_exception_handler (runtime.m:1176)
4   My.Project.iOS                        0x00000001030e2d48 mono_invoke_unhandled_exception_hook (exception.c:1265)
5   My.Project.iOS                        0x00000001031962f4 mono_thread_internal_unhandled_exception (threads.c:5932)
6   My.Project.iOS                        0x00000001030e51b0 mono_gc_run_finalize (gc.c:340)
7   My.Project.iOS                        0x00000001031bbf18 sgen_gc_invoke_finalizers (sgen-gc.c:2773)
8   My.Project.iOS                        0x00000001030e644c finalizer_thread (gc.c:930)
9   My.Project.iOS                        0x0000000103196e08 start_wrapper_internal (threads.c:1222)
10  My.Project.iOS                        0x0000000103196c8c start_wrapper (threads.c:1295)
11  libsystem_pthread.dylib              0x000000019075bd98 _pthread_start + 152
12  libsystem_pthread.dylib              0x000000019075f74c thread_start + 4```
0 Answers
Related