You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 08:05:38