Hi, I am have written multile Microsoft Store Apps in the UWP and WPF frameworks and published them to the Store. These apps all have to 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
#if WINDOWS
StoreContext sc = StoreContext.GetDefault();
var result = await sc.RequestPurchaseAsync("9N35H09Z21");
#endif
It throws error :
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 ...
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)sc; initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
An error occurred: System.InvalidCastException: Invalid cast from 'Windows.Services.Store.StoreContext' to 'MySecureNotes.Components.Pages.Home+IInitializeWithWindow'
Two questions:
- Do I need to add any special nuget packages ?
- 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,
Richard Freytag