Skip to content

AppInstance.FindOrRegisterForKey throws ArgumentException: The parameter is incorrect #5694

Open

Description

@tipa

Describe the bug

While trying to track down crashes, I put var keyInstance = AppInstance.FindOrRegisterForKey("main"); in a try-catch and found that it's throwing an ArgumentException (with message "The parameter is incorrect.\r\n\r\nThe parameter is incorrect") for some of my users.

Steps to reproduce the bug

class Program
{
    [STAThread]
    static void Main()
    {
        try
        {
            var keyInstance = AppInstance.FindOrRegisterForKey("main");
            if (keyInstance.IsCurrent)
            {
                keyInstance.Activated += (_, _) => App.HandleAppActivation();
                Application.Start(p =>
                {
                    var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
                    SynchronizationContext.SetSynchronizationContext(context);
                    _ = new App();
                });
            }
            else { keyInstance.RedirectActivationToAsync(AppInstance.GetCurrent().GetActivatedEventArgs()).GetAwaiter().GetResult(); }
        }
        catch (Exception ex) { **log error** }
    }
}

Expected behavior

No exception

Screenshots

No response

NuGet package version

Windows App SDK 1.7.3: 1.7.250606001

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 LTSC (26100, June Update)

IDE

Visual Studio 2022

Additional context

No response

Activity

  1. added
    area-Lifecycle
    on Aug 7, 2025
  2. ssparach commented on Aug 7, 2025

    @ssparach
    Contributor

    Thank you for your contribution. There are other function calls within the try block. To verify that the exception is specifically caused by AppInstance.FindOrRegisterForKey("main"), could you please try isolating that call and see if the issue still reproduces?

  3. tipa commented on Aug 7, 2025

    @tipa
    Author

    Sorry, I forgot to add the stack trace that was being logged:

    at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32) + 0x42
    at ABI.Microsoft.Windows.AppLifecycle.IAppInstanceStaticsMethods.FindOrRegisterForKey(IObjectReference, String) + 0xe2
    at MyApp.Program.Main() + 0x21
    
  4. tipa commented on Aug 8, 2025

    @tipa
    Author

    I collected some more stack traces:

    System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure
    
    Catastrophic failure
    
       at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32) + 0x42
       at ABI.Microsoft.Windows.AppLifecycle.IAppInstanceStaticsMethods.FindOrRegisterForKey(IObjectReference, String) + 0xe2
       at MyApp.Program.Main() + 0x21
    
    System.Runtime.InteropServices.COMException (0x80040154): Unexpected HRESULT has been returned from a call to a COM component.
       at WinRT.ActivationFactory.ManifestFreeGet(String, Guid, Int32) + 0x12a
       at WinRT.ActivationFactory.Get(String, Guid) + 0x4c
       at Microsoft.Windows.AppLifecycle.AppInstance.get__objRef_global__Microsoft_Windows_AppLifecycle_IAppInstanceStatics() + 0x3e
       at MyApp.Program.Main() + 0x12
    
  5. tipa commented on Sep 22, 2025

    @tipa
    Author

    Another one:

    System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
      at WinRT.ActivationFactory.ManifestFreeGet(String, Guid, Int32) + 0x12a
      at WinRT.ActivationFactory.Get(String, Guid) + 0x4c
      at Microsoft.Windows.AppLifecycle.AppInstance.get__objRef_global__Microsoft_Windows_AppLifecycle_IAppInstanceStatics() + 0x3e
      at MyApp.Program.Main() + 0x12
    
  6. added
    needs-area-owner-attention
    and removed on Sep 28, 2026
  7. benstevens48 commented on Nov 5, 2026

    @benstevens48

    I am also seeing intermittent crashes when calling AppInstance.FindOrRegisterForKey with code like this.

      [STAThread]
      static int Main(string[] args) {
          WinRT.ComWrappersSupport.InitializeComWrappers();
          AppInstance keyInstance = AppInstance.FindOrRegisterForKey("Main");

    Even with the latest WindowsAppSdk 2.6.5. On Windows 11 26H2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Lifecycleneeds-area-owner-attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions