AppInstallManager error - UWP

Anderson Rodrigues Cavalcante 316 Reputation points
2025-02-17T19:10:40.33+00:00

Hello Hello.

I have a sample UWP and the following code is getting error:

private async void Button_ClickAsync(object sender, RoutedEventArgs e)
{
    AppInstallManager appInstallManager = new AppInstallManager();
}

User's image

WinUI works well.

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,305 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 20,526 Reputation points Microsoft Vendor
    2025-02-19T07:12:51.8866667+00:00

    Hello @Anderson Rodrigues Cavalcante ,

    Welcome to Microsoft Q&A!

    The WinUI3 project declares runFullTrust by default, so it worked.

    If you want to call AppInstallManager from a UWP project, you need to declare runFullTrust capabilities and use Windows Application Packaging Project to package UWP and fulltrustprocess APP, then execute AppInstallManager in fulltrustprocess.

    In your UWP solution, add a “Windows Classic Desktop” project to implement your extension. I am adding a C# Console project. Next you need to add a “Windows Application Packaging Project”.

    User's image

    User's image

    Now to connect the two projects we need to declare the extension in the package manifest. For this open the Package.appxmanifest file in the Packaging project (“WapProjTemplate1”) in XML editing mode and add the following section within the <Application> node:

     <Extensions>
       <desktop:Extension
         xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
         Category="windows.fullTrustProcess"
         Executable="ConsoleApp1\ConsoleApp1.exe" />
     </Extensions>
    

    To invoke the extension, we are using the FullTrustProcessLauncher API from the UWP Desktop Extension SDK. Please add Windows Desktop Extension for the UWP in UWP project

    User's image

    In your UWP app code, add a line of code to invoke the desktop extension component. You can place the code below in the button click event.

    if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
    {
      await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
    }
    

    In Console App, Select Target OS version to 10.0.xxxxx.0 , add the code below in Program.cs.

    using Windows.ApplicationModel.Store.Preview.InstallControl;
    Console.WriteLine("Hello, World!");
    string productId = "9WZDNCRFHVFW";  //Microsoft News
    string skuId = "0010";
    AppInstallManager installManager = new AppInstallManager();
    var res = await installManager.StartAppInstallAsync(productId, skuId, false, false);
    Console.WriteLine("App installation started.");
    

    Set the WAPP("WapProjTemplate1") as the startup project, then you can debug the code.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

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