Answered by:
[UWP]crashing when accessing LicenseInformation in Release

Question
-
Hi,
I am currently struggling with a very unusual behavior of my UWP when I switch it to Release mode. Once the code tries to access LicenseInformation, it causes an exception and crashes. Everything works normally in Debug mode. Here is a screenshot of the output:
The weird thing is that this happens even with a dummy simple app and you can reproduce it very easily: Create a new blank UWP app, go to MainPage.xaml.cs and replace it's code with 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(); } }
Switch to Release mode and x86 and try to run the app. It will crash when trying to use LicenseInformation.
Is there something I am missing or is it a bug in UWP?
- Edited by MZetko Tuesday, January 5, 2016 10:52 AM
- Edited by Barry Wang Wednesday, January 6, 2016 6:27 AM titile tag
Tuesday, January 5, 2016 10:52 AM
Answers
-
The equivalent happens with DirectX/C++ apps.
As far as we can tell you need to continue to use the CurrentAppSimulator class all the way to your very final app submission (you cant pass the WACK tests with the CurrentApp class either) then presumably MS do something about fixing the issue when they connect the real IAP store item with the app.... during some kind of validation.
Its not sensible, but that appears to be the 'design'
- Proposed as answer by Barry Wang Wednesday, January 6, 2016 6:27 AM
- Marked as answer by Barry Wang Tuesday, January 19, 2016 10:04 AM
Tuesday, January 5, 2016 1:50 PM -
Hello,
MZetko is correct, this is the expected behavior. The docs for CurrentAppSimulator do mention this but you have to scroll down to the "remarks" section to find it.
"Until the app has been listed in the Windows Store, the CurrentApp object won't work in the app. Use the CurrentAppSimulator to test your app's licensing and in-app products while you develop your app. After you test your app, and before you submit it to the Windows Store, you must replace the instances of CurrentAppSimulator with CurrentApp. Your app will fail certification if it uses CurrentAppSimulator."
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by Barry Wang Wednesday, January 6, 2016 6:27 AM
- Marked as answer by Barry Wang Tuesday, January 19, 2016 10:04 AM
Wednesday, January 6, 2016 2:07 AM
All replies
-
The equivalent happens with DirectX/C++ apps.
As far as we can tell you need to continue to use the CurrentAppSimulator class all the way to your very final app submission (you cant pass the WACK tests with the CurrentApp class either) then presumably MS do something about fixing the issue when they connect the real IAP store item with the app.... during some kind of validation.
Its not sensible, but that appears to be the 'design'
- Proposed as answer by Barry Wang Wednesday, January 6, 2016 6:27 AM
- Marked as answer by Barry Wang Tuesday, January 19, 2016 10:04 AM
Tuesday, January 5, 2016 1:50 PM -
Thank you for the information. I have spent several hours trying to find the reason for this. I hope it is really as you say just a "before-publishing" issue.
I suppose this could be improved - at least mentioning this in the documentation.
Tuesday, January 5, 2016 2:11 PM -
Hello,
MZetko is correct, this is the expected behavior. The docs for CurrentAppSimulator do mention this but you have to scroll down to the "remarks" section to find it.
"Until the app has been listed in the Windows Store, the CurrentApp object won't work in the app. Use the CurrentAppSimulator to test your app's licensing and in-app products while you develop your app. After you test your app, and before you submit it to the Windows Store, you must replace the instances of CurrentAppSimulator with CurrentApp. Your app will fail certification if it uses CurrentAppSimulator."
Thanks,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Proposed as answer by Barry Wang Wednesday, January 6, 2016 6:27 AM
- Marked as answer by Barry Wang Tuesday, January 19, 2016 10:04 AM
Wednesday, January 6, 2016 2:07 AM -
Except that apps cant pass the WACK tests - i.e. part of the certification if they use the CurrentApp class - because they crash.
So you have to run the WACK tests on code which you then change before submitting to the store - how is that sensible...
Wednesday, January 6, 2016 12:19 PM -
Hello,
Don't forget you need to make sure that you handle any exceptions that might come back from the IAP APIs. These APIs may raise exceptions if there is no network connectivity. If the IAPs do fail for some reason your app needs to handle the failure gracefully. One possible solution is to check for network connectivity and disable IAP if there is no network available. You need to come up with a solution that works best for your business model.
I hope this helps,
James
Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
Thursday, January 7, 2016 1:59 AM