Migrating from UWP to Windows App SDK, how to configure ui thread for StoreContext #1866
-
I'm trying to migrate a web app from uwp, it uses webview (now webview2 in winui3) and has some IAPs done through Windows.Services.Store.StoreContext. Documentation has a section about configuring StoreContext for the use with bridge and handling the app's main window, but all calls to the store sdk from the UWP app were working just fine without this configuration. However, the same calls from WinUI3 app throw a But when I add StoreContext configuration code from docs above it crashes on How do I go around these issues and use StoreContext correctly, if it is possible at all? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thanks for reporting this @lospeq, we're looking into this right now! |
Beta Was this translation helpful? Give feedback.
-
Hi @lospeq, the docs for InitializeWithWindow are a bit outdated, the code in the docs works for .NET Core 3 apps but not .NET 5/6 apps. Here's what you should use instead! Use the // Get the StoreContext
var storeContext = Windows.Services.Store.StoreContext.GetDefault();
// Get your HWND
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(m_window);
// And set the HWND on the StoreContext
WinRT.Interop.InitializeWithWindow.Initialize(storeContext, hwnd);
// Then use like normal! We'll get the docs updated! |
Beta Was this translation helpful? Give feedback.
Hi @lospeq, the docs for InitializeWithWindow are a bit outdated, the code in the docs works for .NET Core 3 apps but not .NET 5/6 apps.
Here's what you should use instead! Use the
WinRT.Interop.InitializeWithWindow.Initialize(...)
method as seen below... no need for defining the interface with the GUID anymore 😊We'll get the docs updated!