As Ulugbek Umirov pointed out, the fix is to "double cast".
Imagine that s
represents the expression dailyspring_settings["back_color_b"]
such that the type of the expression is typed as object
, and the object that it evaluates to is an int
(System.Int32).
Thus to first go from object->int
is done with the following Type Cast. A Type Cast changes the type of the expression or "view" of the object, but it does not change or create a new object - as such it will fail with an InvalidCastException if s
does not evaluate to a int
(System.Int32) value.
int i = (int)s;
Now, having an expression typed int
, the next step is int->byte
. This is done with a Type Conversion defined between an expression and a byte. The result is a new value, the byte.
byte b = (byte)i;
So, as suggested, putting it all together:
(byte)(int)dailyspring_settings["back_color_a"]
The above usages of "Type Cast" and "Type Conversion" are to illustrate a point; see the following questions for technical details and terminology.