Without a good, minimal, complete code example that reliably reproduces the problem, it's impossible to know for sure what the problem in your code is.
However, based on the error message it seems likely that the expression package["fault_throw"]
returns type object
, and contains a boxed instance of a float
value.
Under that assumption, all you really need is to unbox the value correctly, and then cast it. E.g. (int)(float)package["fault_throw"]
.
Now, that said: if you don't know in advance what the actual type of the value returned by the expression package["fault_throw"]
is, then the Convert.ToInt32()
method would be appropriate. It can handle a variety of inputs (including string
) and it will do whatever it can to convert the value to an int
.
But if you know for sure the value is a float
(i.e. System.Single
), then it would be more efficient to just unbox the value correctly and cast it (as my example above).