Exception when linking Blazor MAUI apps to Microsoft Store Purchase API Library

I have written multiple Microsoft Store Apps in the UWP and WPF frameworks and published them to the Store. These apps all must and do call the Microsoft Store Purchase API.

Now I’m building a Blazor MAUI Store App and have found apps in the framework can be published to and downloaded from the Microsoft App Store.

However, I encounter a conflict when attempting to call the Microsoft Store Purchase API from my new Blazor MAUI app. This is a critical problem for me.

When I try to write two simple lines in my Blazor MAUI, Home.razor file as follows …
Trying to write two simple lines in Home.razor …

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#if WINDOWS
StoreContext sc = StoreContext.GetDefault();
var result = await sc.RequestPurchaseAsync("9N35H09Z21");
#endif
</code>
<code>#if WINDOWS StoreContext sc = StoreContext.GetDefault(); var result = await sc.RequestPurchaseAsync("9N35H09Z21"); #endif </code>
#if WINDOWS
            StoreContext sc = StoreContext.GetDefault();
            var result = await sc.RequestPurchaseAsync("9N35H09Z21");
#endif

It throws the error …

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>System.Runtime.InteropServices.COMException
HResult=0x80070578
Message=Invalid window handle. (0x80070578)
Consider WindowNative, InitializeWithWindow
Source=WinRT.Runtime
</code>
<code>System.Runtime.InteropServices.COMException HResult=0x80070578 Message=Invalid window handle. (0x80070578) Consider WindowNative, InitializeWithWindow Source=WinRT.Runtime </code>
System.Runtime.InteropServices.COMException
HResult=0x80070578
Message=Invalid window handle. (0x80070578)
Consider WindowNative, InitializeWithWindow
Source=WinRT.Runtime

I also tried this call using the way I had earlier had success with in WPF …

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)sc;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
</code>
<code>IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)sc; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); </code>
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)sc; 
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);

An error occurred on build …

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>System.InvalidCastException: Invalid cast from 'Windows.Services.Store.StoreContext' to 'MySecureNotes.Components.Pages.Home+IInitializeWithWindow'
</code>
<code>System.InvalidCastException: Invalid cast from 'Windows.Services.Store.StoreContext' to 'MySecureNotes.Components.Pages.Home+IInitializeWithWindow' </code>
System.InvalidCastException: Invalid cast from 'Windows.Services.Store.StoreContext' to 'MySecureNotes.Components.Pages.Home+IInitializeWithWindow'

Two questions:

  1. Do I need to add any special NuGet packages ?
  2. Can anyone guide with a working example of how to call the Microsoft Store Purchase API
    from a Blazor MAUI apps that compiles?

Note: Although I’m developing a MAUI Blazor app, I’m currently limited to using it only on Windows. I am doing my development in VS Pro v17.11.2 with all libraries updated to their latest versions.

Thank you very much!

P.S. I can provide a link to a Repo that builds in VS Pro v17.11.2 and shows this error if that is desired.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật