Some doubts regarding after registering for WinUI3 packaged with external location app?

Rohan Pande 265 Reputation points
2024-04-18T11:28:49.1633333+00:00

Hi,

I was earlier creating a WinUI3 blank unpackaged app. Followed the steps here to make my solution from packaged to unpackaged application.

In this project I have disabled the XAML code and created my own entry point (WinMain).

Steps that I have done for disabling the XAML code:
Project Properties > (select All Configurations and All Platforms) > Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions, Edit the value, and add the symbol DISABLE_XAML_GENERATED_MAIN.

This is loading the msix file at run time and the WinMain code:

bool
Register()
{
    Uri                 externaluri = nullptr;
    Uri                 packageuri = nullptr;
    PackageManager      pkgmgr = nullptr;
    AddPackageOptions   options = nullptr;
    bool                registration = false;
    IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation;
    try {
        externaluri = Uri(L"C:\\Users\\rohan.pande\\source\\repos\\DeleteExternalLocation2\\x64\\Debug\\DeleteExternalLocation2");
        packageuri = Uri(L"C:\\Users\\rohan.pande\\source\\repos\\DeleteExternalLocation2\\MyPackage.msix");
        pkgmgr = PackageManager();
        options = AddPackageOptions();
        options.ExternalLocationUri(externaluri);
        deploymentOperation = pkgmgr.AddPackageByUriAsync(packageuri, options);
        HANDLE opCompletedEvent = CreateEvent(nullptr, true, false, nullptr);        // this event will be signaled when the deployment operation has completed.
        deploymentOperation.Completed([&](auto const& depProgress, auto const& status) {
            SetEvent(opCompletedEvent);
            });
        std::wcout << L"Installing package " << packageuri << std::endl;
        std::wcout << L"Waiting for package registration to complete..." << std::endl;
        WaitForSingleObject(opCompletedEvent, INFINITE);
        if (deploymentOperation.Status() == AsyncStatus::Error) {
            hresult deploymentResult = deploymentOperation.ErrorCode();
            int a = 0;
            // OutputDebugStringW (L"Installation Error: %d\n", deploymentOperation.ErrorCode ());
            // OutputDebugStringW (L"Detailed Error Text: %s\n", deploymentResult->ErrorText.Data());
        }
        else if (deploymentOperation.Status() == AsyncStatus::Canceled) {
            OutputDebugStringW(L"Package Registration Canceled\n");
        }
        else if (deploymentOperation.Status() == AsyncStatus::Completed) {
            registration = true;
            OutputDebugStringW(L"Package Registration succeeded!\n");
        }
        else {
            OutputDebugStringW(L"Installation status unknown\n");
        }
    }
    catch (const std::exception& ex) {
        std::wcout << L"AddPackageSample failed, error message: " << ex.what() << std::endl;
        std::wcout << L"Full Stacktrace: " << ex.what() << std::endl;
    }
    return registration;
}


int CALLBACK
WinMain([[maybe_unused]] HINSTANCE pInstance, [[maybe_unused]] HINSTANCE pPrevInstance, [[maybe_unused]] LPSTR pCmdLine, [[maybe_unused]] int pShowCmd)
{

    Register ();
    winrt::init_apartment(winrt::apartment_type::single_threaded);
     Application::Start([](auto&&) {
           ::winrt::make<::winrt::DeleteExternalLocation2::implementation::App>();
    });
} 

Now I am currently moving my existing solution trying to move to package with external location as this provides 'package identity' which provides additional features to my app.

Reference: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/grant-identity-to-nonpackaged-apps

It registers the package identity for the first time and application runs (only for first time) but from next time the applications doesn't run. Any idea why this happens like that? I didn't understand why this is happening? Can somebody help here?

Granting the package identity documentation shared above is for unpackaged apps, right? So, it should run that's my understanding.

Note: I don't have any extra code you could also try by creating a new project make it as unpackaged and just follow the steps for disabling the XAML code and follow the steps of granting the package identity.

This is the error that comes on the output screen:

User's image

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
726 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,531 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 11,496 Reputation points Microsoft Vendor
    2024-04-22T08:11:31.49+00:00

    @Rohan Pande, as this issue is complex, you can open an incident at https://developer.microsoft.com/en-us/windows/support/?tabs=Contact-us so that our engineer can work with you closely and please choose the 'Other' for Windows App SDK for this issue. In-addition, if the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged.

    0 comments No comments