Desktop Bridge打包WPF应用内购异常:StorePurchaseStatus.NotPurchased且ExtendedError为null
WPF Desktop Bridge应用Windows 11内购异常问题
通过Desktop Bridge打包的WPF应用存在内购问题:部分Windows 11用户无法购买插件,调用内购接口后返回StorePurchaseStatus.NotPurchased状态,且result.ExtendedError为null,仅显示“Canceled”提示。
应用的目标框架配置如下:
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
以下是简化后的采购逻辑代码:
namespace MyApp { public partial class MainWindow: Window { private readonly StoreContext context; public MainWindow(){ context = StoreContext.GetDefault(); } private bool IsAdministrator() { var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator); } private async void BuyButtonClick(object sender, RoutedEventArgs e) { if (IsAdministrator()) { ShowAlert("Cannot run under administrator rights"); return; } if (sender is Button button) { StoreProduct? storeProduct = ((Product)dataContext).storeProduct; if (storeProduct != null) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(async delegate { var hwnd = new WindowInteropHelper(this).Handle; WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd); var result = await context.RequestPurchaseAsync(storeProduct.StoreId); switch (result.Status) { case StorePurchaseStatus.Succeeded: ShowAlert("Succeeded"); break; case StorePurchaseStatus.AlreadyPurchased: ShowAlert("AlreadyPurchased"); break; case StorePurchaseStatus.NotPurchased: var extendedError = result.ExtendedError; if (extendedError != null) { ShowAlert(extendedError.Message); } else { ShowAlert("Canceled"); } break; case StorePurchaseStatus.NetworkError: ShowAlert("NetworkError"); break; case StorePurchaseStatus.ServerError: ShowAlert("ServerError"); break; } })); } } } } }
该代码在本人的Windows 10和Windows 11设备上均可正常运行,但上述问题出现在部分Windows 11用户端。
内容的提问来源于stack exchange,提问作者JaSHin
相关产品推荐
相关产品推荐

