I'm building a WinRT CLI wrapper in C# that checks if a user owns an active Microsoft Store subscription add-on. This CLI is called from an Electron + React.js app using command-line arguments and returns true or false depending on the license status.
Problem
The CheckSubscription command incorrectly returns false, even though the logged-in user does have an active subscription to the add-on.
Below is the code snippet
private static async Task HandleCheckSubscriptionCommand(string[] args)
{
string addonId = args[1];
var context = StoreContext.GetDefault();
var license = await context.GetAppLicenseAsync();
foreach (var kvp in license.AddOnLicenses)
{
var addOnLicense = kvp.Value;
if (addOnLicense.SkuStoreId.Equals(addonId, StringComparison.OrdinalIgnoreCase))
{
bool isValid = addOnLicense.IsActive && addOnLicense.ExpirationDate > DateTimeOffset.UtcNow;
Console.WriteLine(isValid ? "true" : "false");
return;
}
}
Console.WriteLine("false");
}
What could cause GetAppLicenseAsync() to return a subscription license as inactive or missing, even though the user has purchased it through the Store?
I've also done the following:
- MSIX-packaged CLI app (Windows 10+), wrapper is included and succesfully ran by application
- Published to Microsoft Store (delisted for testing)
- Using
StoreContext.GetAppLicenseAsync() - Subscription add-on is published and testable
- The add-on ID resolves correctly via the API