LoginSignup
1
0

More than 5 years have passed since last update.

Galaxy端末系におけるSerializationException

Last updated at Posted at 2015-04-07
I/Unity﹕ SerializationException: Field "Test" not found in class HogeFuga

Galaxy系端末でのみ上記のようにシリアライズのExceptionが発生したのでメモ

そもそもリフレクションとか使って色々あってInterfaceを実装したクラスをシリアライズしたかった。
そのため、パブリックなfieldではなくpropertyをシリアライズの対象とする必要があった。
その際、下記のようなコードだと端末によってExceptionが発生したのであった。。。

解決方法としては自動プロパティ使えよってことなんだけど、そもそもなんで自動プロパティ使わなかったかは・・・忘れたw(そもそもC#にまだ慣れてない)

他の解決方法としてDataContracやDataMember系のAttribute使うとイケそうなんだけどUnityとMonoのVersionの関係上これは使えそうになかった。

ダメだったコード

C#
[System.Serializable()]
public class HogeFuga : IFuga
{
  private int test;
  public int Test { get {return this.test;} set {this.test = value;} }
}

public interface IFuga
{
  int Test { get; set; }
}

問題なく動作したコード

C#
[System.Serializable()]
public class HogeFuga : IFuga
{
  public int Test { get; set; }
}

public interface IFuga
{
  int Test { get; set; }
}

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0