Share via

Why does AppInstance.GetInstances() occasionally throws "Class not registered"?

Hong 1,526 Reputation points
2023-09-12T13:34:07.5366667+00:00
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
           try            
           {
                if (AppInstance.GetInstances().Count == 0)
                 {
                     PCLUtility.AddLog("First Instance");                 
                 } 
                 else 
                 {
                 }
            }
            catch (Exception ex)             
            {
            }
         }


GetInstances() occasionally throws the following:

 Stack Trace:
   at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
   at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Void*) + 0xbe
   at __Interop.ForwardComStubs.Stub_3[TThis, TResult](__ComObject, Int32) + 0x37
   at Windows.ApplicationModel.AppInstance.GetInstances() + 0x2c
   at MyApp.App.<OnLaunched>d__33.MoveNext() + 0x926

It is not a big deal because it is rare. I am curious about the possible causes.

Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.