Bug 33630 - Applications.Properties do not persist
Summary: Applications.Properties do not persist
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-03 18:55 UTC by Ian Geoghegan
Modified: 2015-10-16 01:55 UTC (History)
6 users (show)

Tags:
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 ANSWERED

Description Ian Geoghegan 2015-09-03 18:55:55 UTC
From custom classes decorated with the DataContract attribute to simple strings, property values and keys fail to persist from one running of the application to the next. Demonstrated in office.

App.OnStart code:

            if( !Properties.ContainsKey( "testKey" ) )
            {
                Debug.WriteLine( "TestKey not found in properties; creating accordingly. || App.OnStart()" );
                Properties.Add( TestKey, "Test key!!!" );
                SavePropertiesAsync();
            }

Will fire each successive execution of the application.
Comment 1 Paul DiPietro [MSFT] 2015-09-04 10:48:47 UTC

*** This bug has been marked as a duplicate of bug 31000 ***
Comment 2 Ian Geoghegan 2015-09-04 10:53:09 UTC
This is NOT a duplicate of 31000 as it can be reproduced with a string value. This string value can not have a DataContract attribute associated with it.
Comment 3 Ian Geoghegan 2015-09-04 10:56:19 UTC
Forgot to mention: this bug still evinces itself with an class instance decorated with a DataContract attribute and associated properties decorated with DataMember attributes.
Comment 4 Paul DiPietro [MSFT] 2015-09-04 11:11:35 UTC
Please create a buildable reproduction project. Thanks.
Comment 5 Ian Geoghegan 2015-09-04 14:07:36 UTC
https://github.com/xamarin/xamarin-forms-samples/tree/ed570a57f66e5f29f4c234e6d3d7423a42abefc5/Todo/PCL

Repro steps:

1. Download
2. Set iOS as startup project.
3. Run once. Note debug output.
4. Stop debugging.
5. Run second time. Note debug output.
Comment 6 Ian Geoghegan 2015-09-09 18:56:03 UTC
Repro steps provided above. Thanks.
Comment 7 Rui Marinho 2015-10-14 10:44:40 UTC
Hey Ian, i m not able to reproduce the problem, i think you are not reading the code correctly .

To test using the Todo sample you should tap one of the items first, them you have to change the app to "Sleep" mode, you can tap the Android home button for example. You will see in the log:

setting ResumeAtTodoId = 7
OnSleep saving ResumeAtTodoId = 7

The properties is only saved when the app goes into to sleep mode, like for example when going to home or switching to another app:

https://github.com/xamarin/xamarin-forms-samples/blob/ed570a57f66e5f29f4c234e6d3d7423a42abefc5/Todo/PCL/Todo/App.cs#L57

Now if you do that, you can stop the app, run it again and you will see in the log:

OnStart
   rati=7

Thanks

Warm Regards
Xamarin Forms Team
Comment 8 Ian Geoghegan 2015-10-14 10:56:18 UTC
Rui,

Thank you. I think I misunderstood - I thought that properties were meant to persist from one execution of the app to the next. Thank you for clarifying this, and my apologies for the confusion.

Ian
Comment 9 Ian Geoghegan 2015-10-15 03:16:48 UTC
Rui,

I re-read your post; tried the sample again and got the error to happen. Then I tried again and nothing. I have been trying for hours, cleaning my solution, cleaning the sample solution, and I have no idea why my project fails each time to persist the properties while the demo does not. I re-factored; duplicated the code in the sample in my own solution. Still it fails on my side but not in the sample.

My question is this: how can I debug what is going on behind the scenes? How can I dig deeper and find out what is going on? 

Thanks,

Ian
Comment 10 Rui Marinho 2015-10-15 07:32:11 UTC
can you email me your sample code?
Comment 11 Ian Geoghegan 2015-10-16 01:55:02 UTC
Rui,

Emailed you the code; spent another day testing. The behavior seems non-deterministic - or at least, I can't tell what is making it happen when. Did you get to check out what I sent you?

Thanks,

Ian