Bug 57348 - Xamarin Forms assumes Application Settings is used, does not check for null before attempting to deserialize in SavePropertiesAsync
Summary: Xamarin Forms assumes Application Settings is used, does not check for null b...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.4
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-09 22:11 UTC by Scott Davis
Modified: 2017-08-16 23:09 UTC (History)
3 users (show)

Tags: applicationproperties, windows
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Scott Davis 2017-06-09 22:11:30 UTC
Please add a check to your code to see if the Application properties are null before you attempt to deserialize them.  I don't use app properties. I have 25000 crashes in Xamarin Insights because of this.  This causes the WinPhone 8.1 version of my app to crash on every suspend.

Also, these event methods should be virtual so we can override them and trap your errors.

This is the stack trace from insights. 
------------------------------

System.Runtime.Serialization.SerializationExceptionThere was an error deserializing the object of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]. '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.
Raw
System.Threading.Tasks.Task.ThrowIfExceptional(bool includeTaskCanceledExceptions)
System.Threading.Tasks.Task<_>.GetResultCore(bool waitCompletionNotification)
System.Threading.Tasks.Task<_>.get_Result()
Xamarin.Forms.Application.get_Properties()
Xamarin.Forms.Application.<SetPropertiesAsync>d__74.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Xamarin.Forms.Application.<SavePropertiesAsync>d__51.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Xamarin.Forms.Platform.WinRT.WindowsBasePage.<OnApplicationSuspending>d__9.MoveNext()
System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(object state)
System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
System.Runtime.Serialization.SerializationExceptionThere was an error deserializing the object of type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]. '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.
Comment 1 David Ortinau [MSFT] 2017-06-23 14:58:20 UTC
Scott,

Can you submit a simple project that demonstrations this issue? We are investigating, but as yet are unable to reproduce the crash.

Are you targeting more than WinPhone 8.1?
Comment 2 Scott Davis 2017-06-23 17:32:25 UTC
What do you mean by targeting more than WP8.1.  I'm building an 8.1 app for Windows Phone, WP 10 can also run a WP8.1 app.  I don't see this crash on Android or iOS (WinRT is in the stacktrace).  I hope that answers the question you were getting at.

I don't believe this happens on every app suspend, for all windows phones, but I am not sure.  Your reproduction may not be 100% reliable.

Am I wrong? Is there a way I can override this Xamarin.Forms.Platform.WinRT.WindowsBasePage.OnApplicationSuspending event and trap the error?  I can't find which of my pages would inherit from this object so I could override the method and trap the error.
Comment 3 Scott Davis 2017-07-27 15:02:42 UTC
PING. Is there an update on this?  I checked today 23,000 crashes in the last month in Xamarin insights for this crash.  I discovered today that this crash seems to be interrupting Windows Store purchase transactions.  The app crashes when I go to the store checkout, (because of suspend).  When the app resumes, the receipt is not part of the retry logic to check for unfulfilled transactions.  This bug is going to force me to remove IAP from my app because I can't even use the fulfillment retry logic. Customers are getting mad about lost purchases.  This is no longer about upset customers, this is hurting my revenue model and threatening the survival of my company.

You don't need an repo solution from me.  OnAppSuspending should never throw a fatal exception. Trap it and discard it, or let me override the event so I can.
Comment 4 David Ortinau [MSFT] 2017-08-16 23:09:25 UTC
Hi Scott,

This issue looks to be addressed by 

https://github.com/xamarin/Xamarin.Forms/pull/1036

It is available here:

https://www.nuget.org/packages/Xamarin.Forms/2.4.0.266-pre1

Apologies for not seeing your message earlier. The ticket somehow went to a status of IN_PROGRESS which meant we didn't see it during our sweep of NEEDINFO.