0

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?

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91

2 Answers2

1

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.

pumpkinszwan
  • 1,312
  • 11
  • 21
  • When I changed my code from `CurrentAppSimulator` to `CurrentApp` it did not only crash on my personal computer, but also in the certification process. How do I fix that? Obviously the app has not been published at that point, but I also cannot use `CurrentAppSimulator`, because the package getting certificated will also be in the Store eventually ... – heroxav Feb 28 '17 at 15:18
0

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.

Ask Too Much
  • 627
  • 4
  • 19
  • I know that this is possible for debugging, but release mode should behave nicely even before it is uploaded to Store (this was the case always, at least) – Martin Zikmund Jan 05 '16 at 10:46