C#: Unable to cast object of type 'System.Int64' to type 'System.Int32'
You must first unbox the value as the dictionary's value type is object
.
Dictionary<object, object> dict = ...
Color = (int)(long)dict.GetValue("color");
If you don't know the original type, the following idiom may be more convenient.
public T Get<T>(string key)
{
return (T) Convert.ChangeType(_dict[key], typeof(T), CultureInfo.InvariantCulture);
}