0

I am serializing an array of Color[]. Assigning some values of Color to it at the time of serializing.

ColorList = new Color[] { Color.Red, Color.Blue, Color.Black, Color.Yellow };

At the time of deserialization, I am getting the object back with same array length but the values aren't there. Here is what I am getting -

{Name=0, ARGB=(0, 0, 0, 0)}
Arpit Gupta
  • 1,209
  • 1
  • 22
  • 39

1 Answers1

1

System.Drawing.Color cannot be represented as RGBA upon serialization. You need to represent it as a color code, and de-code it later on.

You would have to use a string array with the RGBA values like this:

ColorList = new string[] { 
    string.Format("{0},{1},{2},{3}", Color.Red.R, Color.Red.G, Color.Red.B, Color.Red.A),
    string.Format("{0},{1},{2},{3}", Color.Black.R, Color.Black.G, Color.Black.B, Color.Black.A),
    string.Format("{0},{1},{2},{3}", Color.Yellow.R, Color.Yellow.G, Color.Yellow.B, Color.Yellow .A)
}
Koby Douek
  • 16,156
  • 19
  • 74
  • 103