What is the possible cause of IndexOutOfRangeException for coreDispatcher.RunAsync()?

Hong 1,186 Reputation points
2023-10-26T15:38:40.63+00:00
            try
            {
                await coreDispatcher?.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ...

                    });
            }
            catch (Exception ex)
            {
                ...
            }


The above code throws the following IndexOutOfRangeException occasionally:

 Stack Trace:
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowIndexOutOfRangeException() + 0x25
   at System.Collections.Generic.Internal.DictionaryBase.FindFirstEntry(Int32) + 0x6d
   at System.Collections.Generic.Internal.HashSet`1.FindFirstKey(TKey&, Int32) + 0x18
   at System.Runtime.InteropServices.CCWLookupMap.GetOrCreateCCW(Object, RuntimeTypeHandle, IntPtr&) + 0x69
   at SharedLibrary!<BaseAddress>+0x8624e0
   at SharedLibrary!<BaseAddress>+0x86249c
   at SharedLibrary!<BaseAddress>+0x86241f
   at System.Runtime.InteropServices.McgMarshal.ObjectToComInterface(Object, RuntimeTypeHandle) + 0xb1
   at System.Runtime.InteropServices.McgMarshal.DelegateToComInterface(Delegate, RuntimeTypeHandle) + 0x41
   at Windows.UI.Core.ICoreDispatcher__Impl.Stubs.RunAsync(__ComObject, CoreDispatcherPriority, DispatchedHandler) + 0x2f

Could anyone offer a tip about the possible causes?

Universal Windows Platform (UWP)
{count} votes