0
votes

I cannot run my UWP app in Release mode, because it always crashes right away when somewhere in my code I am trying to access the CurrentApp.LicenseInformation.

enter image description here Steps to reproduce: Create a new blank UWP app. Go to MainPage.xaml.cs and add the following:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        Loaded += MainPage_Loaded;
    }

    private void MainPage_Loaded( object sender, RoutedEventArgs e )
    {            
        ProductIapTextBlock.Text = CurrentApp.LicenseInformation.ProductLicenses[ "hello" ].IsActive.ToString();
    }
}

Now change to Release mode and x86 platform and try to run the app. It should crash with the errors as in the image above.

What is wrong here? Is the problem hidden in my code or is it a problem in UWP?

2
Seen, but it doesn't help.This is a very simple and basic scenario, not a Windows Phone 8.1 app. That is why it is even bigger problem.Martin Zikmund
But did you checked your Window Store account to see if everything is filled in?Gusman
Yes I did. It works with any other app I get from Store.Martin Zikmund

2 Answers

1
votes

According to this documentation : https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.store.licenseinformation.aspx

The app needs to be published in the Store for the CurrentApp.LicenseInformation query to work. So while developing the only option you have is to use the simulator version, then change your code when you are ready to upload to the store.

If your code works with the simulated licence check it should work in the live store. However, I am planning on publishing my app as hidden in the store (i.e. only available from direct link, not searchable) to test. Then I will release to the Store properly if it works.

0
votes

Use compilation directives, define directives on first line of your code.

#define DUMMY_STORE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;

namespace SO
{
    public class LicenseManager
    {
        private readonly Dictionary<string, bool> _dummyLicense;

#if DUMMY_STORE
        public LicenseManager()
        {
            // Init license for testing only
            _dummyLicense = new Dictionary<string, bool>
            {
                {"hello", true}
            };
        }
#endif

        public bool IsActive(string feature)
        {
#if DUMMY_STORE
            return _dummyLicense[feature];
#else
            return CurrentApp.LicenseInformation.ProductLicenses[feature].IsActive;
#endif
        }
    }
}

Replace your code with this :

private void MainPage_Loaded( object sender, RoutedEventArgs e )
{            
     ProductIapTextBlock.Text = new LicenseManager.IsActive("hello").ToString();
}

And don't forget to comment #define DUMMY_STORE before you upload it to the store.