microsoft / microsoft/microsoft-ui-xaml
Interaction of Windows Store fails when running as an escalated process
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
When running a WinUI3 application as admin via
```
```
then calling either of
`var result = await context.RequestPurchaseAsync(addOn.StoreId);`
or
`var result = await addOn.StoreProduct.RequestPurchaseAsync();`
results in the windows store dialog closing immediatley after it has opened, without making an AddOn purchase.
Sorry I can't give you a full code example, as that would require my AddOn keys and partner login :-)
```
context = StoreContext.GetDefault();
context.OfflineLicensesChanged += LicensesChanged;
// Initialize the context with the window handle (HWND).
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
WinRT.Interop.InitializeWithWindow.Initialize(context, hWnd);
//Note A StoreProduct that represents a subscription add-on has the type Durable.
//https://learn.microsoft.com/en-us/uwp/api/windows.services.store.storeproduct.productkind?view=winrt-26100#windows-services-store-storeproduct-productkind
var response = await context.GetAssociatedStoreProductsAsync(["Durable", "Consumable"]);
if (response.ExtendedError == null)
{
RegionAnalysisSubscription.UpdateProduct(response.Products);
}
public void UpdateProduct(IReadOnlyDictionary products)
{
var found = products.Values.FirstOrDefault(p => p.StoreId == StoreId);
if (found == null)
{
return;
}
CanPurchase = found != null;
CanFreeTrial = found != null
&& found.Skus.Any(sku => sku.SubscriptionInfo.HasTrialPeriod);
StoreProduct = found;
}
public async Task Purchase(WindowsStoreAddonViewModel addOn)
{
if (addOn.StoreProduct == null)
{
throw new InvalidOperationException($"AddOn {addOn.StoreId} is not purchasable");
}
var result = await //context.RequestPurchaseAsync(addOn.StoreId);
addOn.StoreProduct.RequestPurchaseAsync();
log.InfoLine($"Purchase of {addOn.StoreProduct.Title}=>{result.Status}");
if (result.ExtendedError != null)
{
log.ErrorLine(result.ExtendedError.ToString());
}
await UpdateProducts();
return result.Status;
}
```
### Steps to reproduce the bug
Build an application that requires Admin
Register on WIndowsStore
Generate an AddOn
Attempt to buy the AddOn
### Expected behavior
I expect the Windows Store dialog not to close immediately and allow purchase
### Screenshots
Non elevated

Elevated
https://github.com/user-attachments/assets/ec3d235c-a7dd-4777-9284-27f2e0ce0839
### NuGet package version
WinUI 3 - Windows App SDK 1.7.1: 1.7.250401001
### Windows version
Windows Insider Build (xxxxx)
### Additional context
Expecting someone to say "Literally costing me money" 😃
Could this be related to the known issues with FileOpen / FileSave dialogs when runnning as Admin?
Trying to use a FileOpenPicker while running the app as Administrator will crash the app https://github.com/microsoft/microsoft-ui-xaml/issues/2504
Contributor guide
Research direction
Start by reproducing the issue with the manifest's requestedExecutionLevel set to requireAdministrator, then trace StoreContext initialization and the two RequestPurchaseAsync entry points shown in the report. Compare elevated and non-elevated behavior using the provided Windows Store add-on flow; done means the elevated Store dialog stays open and permits the purchase.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100