I just recompiled my project with Xamarin.Forms 2.0 and found Application.Current.SavePropertiesAsync is not working as expected in "Release" mode.
I used the following code to save the login email
Application.Current.Properties ["LoginEmail"] = loginInfo.Email; await Application.Current.SavePropertiesAsync ();
and then load it when the app starts.
if (Application.Current.Properties.ContainsKey ("LoginEmail")) {
c_email.Text = (string)Application.Current.Properties ["LoginEmail"];
}
But now, I cannot load the saved email any more. The strange thing is, it still works in debug mode. Can anyone help me out?. It will be a big headache for me to rollout an update.
Thanks.
@Vincentwx In the meantime, this workaround might help:
Create a custom linker configuration file: https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/
Set the contents of that file to:
<?xml version="1.0" encoding="utf-8" ?> <linker> <assembly fullname="System.Runtime.Serialization"> <namespace fullname="System.Runtime.Serialization" /> </assembly> </linker>
And try your Release build with the Linker turned on.
Answers
Have a look here:
https://forums.xamarin.com/discussion/55993/application-current-properties-dont-work-in-xamarin-2-0
I now use the Xamarin.Plugin Settings, works fine!
@karbo, thanks for the suggestion. I can use that plug in for a new app, but cannot use it on the current app for an update.
@Vincentwx Which platforms are you experiencing this problem on? Does it consistently work in Debug mode on all platforms? Does it consistently fail in Release mode on all platforms?
Hi E.Z.
My project is only on Android for now. I don't know if it's the same issue or not on other platforms. My environment is the latest Xamarin Studio on window with Xamarin.Forms 2.0. The device is Samsung Galaxy 3. The problem is consistent as I described in my environment.
Thanks for looking into it.
Here are more details about my project (Please let me know if you need a specific setting in my project)
Xamarin.Forms 2.0.0.6484.
Xamarin Studio
Version 5.10 (build 871)
Installation UUID: 746773da-aa82-4843-8c4a-d8310009ec85
Runtime:
Microsoft .NET 4.0.30319.42000
GTK+ 2.24.23 (MS-Windows theme)
GTK# 2.12.30
Xamarin.Profiler
Not Installed
Xamarin.Android
Version: 6.0.0 (Indie Edition)
Android SDK: C:\Users\vincentw.AMPM\AppData\Local\Android\android-sdk
Supported Android versions:
2.3 (API level 10)
4.0.3 (API level 15)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23
Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)
Xamarin Android Player
Version: 0.4.4
Location: C:\Program Files\Xamarin Android Player\DeviceManager.exe
Build Information
Release ID: 510000871
Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
Build date: 2015-11-12 07:16:34-05
Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
Build lane: monodevelop-windows-cycle6
Operating System
Windows 10.0.10240.0 (64-bit)
My Project Settings:
Please check attached screenshot
@Vincentwx Do you have linking enabled for your project?
@EZHart I am not sure which option you mean, can you show me a screenshot where to check it?
@Vincentwx In your Android project properties, under Build -> Android Build, select the Linker tab. What is 'Linker behavior' set to?
I have the same setting as yours. Here is the screenshot attached. However. please be aware I am using xamarin studio on Windows, not on MAC
@Vincentwx Can you try changing your setting to "Don't Link" and see if you still have the issue with the properties in Release mode?
I'm not suggesting that as a real workaround, I'm just trying to eliminate some possibilities.
@EZHart. I changed to "Don't Link" and it fixed the problem. Now I can save and load the settings. Can I expect a fix in the next release?
Thanks.
@Vincentwx I can't speak to the timeline for a fix just yet, but this definitely gets us closer. Thank you for the update!
@Vincentwx In the meantime, this workaround might help:
Create a custom linker configuration file: https://developer.xamarin.com/guides/cross-platform/advanced/custom_linking/
Set the contents of that file to:
And try your Release build with the Linker turned on.
@EZHart Thanks for looking into it. I don't want to rush to use the customer linking. I will wait for a fix.
any update on this?
I have the same problem in "Release" mode. That is fixed using "Don't link".
A drawback is that the package creation fails using "Don't link" and LLVM, therefore is not possible to use LLVM in the release package.
@EZHart the custom linker configuration has worked for me:
@EZHart How close is it that this problem will be fixed in the next release? I am still waiting for it.
Frustrating. I get the issue even in Debug mode (on Android). I'm moving all my Application.Current.Properties read/writes to use SqlLite instead.
@EZHart I just did a test on the latest stable release, this bug is still not fixed. In the pre-release version, there is no mention about any fix either. Is there any chance this bug is going to be fixed at all?
@EZHart Would the linker tag with
System.Runtime.Serialization
solve this debugging problem? https://forums.xamarin.com/discussion/59391/vs2015-debugger-freezes-on-initial-run#latest I can't figure out why this dll is causing me trouble on Android.The custom linker configuration workaround from @EZHart in this thread worked for me.
@Vincentwx Have you updated to Xamarin.Android 6.0.1? There are multiple bugs related to the Application Properties, and there was a fix in that version which may address your issue.
If the issue is still occurring with that version, does the Android console display any messages with the category "Xamarin.Forms PropertyStore"?
@EZHart I have it, Version: 6.0.1.10 (Indie Edition), on my machine(Windows). When I did the test on Feb 11, I made sure everything about Xamarin was up to date. But I don't know if this version was released before that. I still prefer not using the Customer Linker Configuration, but I moved on with it anyway. Thanks