Bug in OracleDataReader causing InvalidCastException?

Just had a weird error where loading a small dataset from an Oracle database was sometimes causing an invalid cast exception “Specified cast is not valid” on the dataset Fill method.

There was nothing wrong with the execution of the procedure, and the exception was happening within the oracle ADO classes. Specifically:

Stack: at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValues(Object[] values)

I tried changing it to use a datareader and as you can see, I can read the value with GetFloat but not with GetDecimal. The value is also not some out of control decimal value with 38 places after the decimal point. And, you can see that it fully believes that the datatype is Decimal.

We found through trial and error that if we truncate the data in Oracle to only 2 decimal places that this stops the errors, but we are not sure why we are getting these results.

I thought I would post in case others came across this.

2015-07-30 10_27_45-Clipboard