locked
StoreContext in Desktop Bridged Application - InvalidCastException RRS feed

  • Question

  • I am trying to access the StoreContext object in my Win32 application in a Desktop Bridge.

    When trying to convert the StoreContext object to assign the Window used for displaying dialogs etc.,  I get a "InvalidCastException". See the code piece below for clarification. What is going wrong here, this codepiece is basically copied from the Microsoft Tutorials.

            async void InitStoreContext()
            {
                storeContext = StoreContext.GetDefault();
    //the line below trows an InvalidCastException
                IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext;
                initWindow.Initialize(new WindowInteropHelper(_actionBar).Handle);
    
                storeContext.OfflineLicensesChanged += OfflineLicensesChanged;
    
            }

    • Moved by CoolDadTx Thursday, October 25, 2018 3:01 PM UWA related
    Thursday, October 25, 2018 1:20 PM

Answers

  • Hey Roy, thanks for your aswer. It turned out thst I did define the correct function but I changed the GUID of the function. This causws the error. So for anyone with the same problem, use the same GUID as in the samples.
    • Marked as answer by poochie89 Friday, October 26, 2018 6:59 AM
    Friday, October 26, 2018 6:58 AM

All replies

  • Hi,

    How do you defined the InitializeWithWindow? have you defined it like this:

     // This interface definition is necessary because this is a non-universal
        // app. This is part of enabling the Store UI purchase flow.
        [ComImport]
        [Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        public interface IInitializeWithWindow
        {
            void Initialize(IntPtr hwnd);
        }

    There is a sample about how to implement In-app purchase here:StoreSample. You could take a look at the StoreConsumableHelper.cs for more information.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 26, 2018 6:28 AM
  • Hey Roy, thanks for your aswer. It turned out thst I did define the correct function but I changed the GUID of the function. This causws the error. So for anyone with the same problem, use the same GUID as in the samples.
    • Marked as answer by poochie89 Friday, October 26, 2018 6:59 AM
    Friday, October 26, 2018 6:58 AM