firebase 实时数据库 - Xamarin Android 应用程序无法在发布模式下解析 Android.Graphics.Color,但在调试模式下一切按预期工作



由于某些原因,FirebaseClient(FirebaseDatabase.net(在发布模式下无法解析我的数据类中的Android.Graphics.Color对象,但在调试模式下它可以正常工作。

表的Firebase观察器:

private readonly FirebaseClient firebaseClient = new FirebaseClient(...);
...
firebaseClient.Child("Tables")
                          .AsObservable<Table>()
                          .Subscribe(d =>
                          {
                              if (d.Object != null)
                              {
                                  Table table = d.Object;

                                  // ...
                              }
                          });

表类

public class Table
{
        public int Id { get; set; }
        public byte SeatsNum { get; set; }
        public List<Guest> Guests { get; set; }

        [JsonConstructor]
        public Table(int id, byte seatsNum)
        {
            Id = id;
            SeatsNum = seatsNum;
            Guests = new List<Guest>();
        }

        public Table(int id, byte seatsNum, List<Guest> guests)
        {
            Id = id;
            SeatsNum = seatsNum;
            Guests = guests ?? new List<Guest>();
        }
}

客用级

public class Guest
{
        public string Name { get; }
        public Color  BackgroundColor { get; }
        public Color TextColor { get; }
        public List<string> Tags { get; }
        public int TableId { get; }
        public bool Checked { get; set; }

        public Guest(string name, int tableId)
        {
            Name = name;
            ColorService colorService = new ColorService();
            (Color backgroundColor, Color textColor) = colorService.GetRandomColor();
            BackgroundColor = backgroundColor;
            TextColor = textColor;
            Tags = new List<string>();
            TableId = tableId;
            Checked = false;
        }

        public Guest(string name, int tableId, params string[] tags)
            : this(name, tableId)
        {
            Tags = tags.ToList();
        }

        [JsonConstructor]
        public Guest(Color backgroundColor, bool Checked, string name, int tableId, List<string> tags, Color textColor)
        {
            Name = name;
            BackgroundColor = backgroundColor;
            TextColor = textColor;
            Tags = tags ?? new List<string>();
            TableId = tableId;
            this.Checked = Checked;
        }
}

在调试模式下,一切都很好,但当我将应用程序切换到发布模式并重建项目时,由于某些原因,Color对象为(R,G,B,A(=(0,0,0,0(,数据类的所有其他属性都会成功解析。

我已经解决了我的问题,将BackgroundColor和TextColor保存为字符串,并在需要时在Color对象中手动转换它们。但是,我感兴趣的是,什么问题会导致从调试模式下的正常行为到发布模式下的失败?

您可以检查此文档(配置链接器(。

链接器然后丢弃所有未使用(或引用(的未使用的程序集、类型和成员。

这可能会导致在发布模式下忽略一些有用的程序集。

最新更新