xamarinxamarin-linker

Xamarin Linker stipping out static class properties?


In VS 2013, Xamarin Forms.

Our Android & IOS app has a static class:

public static class CacheKeys
{
    public static string RememberMeEmail = "RememberMeEmail";
    public static string RememberMeSwitch = "RememberMeSwitch";
}

This class is stripped by the linker in the iOS device debug build, but not in the simulator or Android.

See attached screenshot.

I have set the Debug Linker for iPhone to Do Not Link, yet this static class is removed.

??????

enter image description here


Solution

  • You can set a preserve attribute to your class: http://developer.xamarin.com/guides/ios/advanced_topics/linker/ See the section: Preserving Code

    Example:

    [Preserve]
        public static class LinkerPreserve
        {
            static LinkerPreserve()
            {
                throw new Exception(typeof(SQLitePersistentBlobCache).FullName);
            }
        }
    
        public class PreserveAttribute : Attribute
        {
        }