SamSaffron/MiniProfiler — pull request #10 by vcsjones (2011-12-07 22:37:03+00:00)
Title: System.Data.OracleClient.OracleParameter.Size may throw exception

When using ProfiledDbConnection, the System.Data.OracleClient.OracleParameter.Size may throw an InvalidOperationException if the OracleParameter.Value is OracleBinary.Null or OracleString.Null and the Size property on the parameter is not explicitly set.

The Microsoft SqlParameter will return 0 if the value is of SqlString, SqlChars, SqlBinary, etc. See SqlParameter.ValueSize in Reflector.

However, The OracleParameter will just let the exception be thrown instead of returning zero. This causes a problem in the SqlTiming class which attempts to get the size of every parameter.

This actually appears to be a bug in the OracleParameter class, as it does check for null, but after it will actually throw the exception.

The fix is to check if the parameter value is INullable, if it is, and IsNull is true, return zero (which is consistent with how SqlString, SqlChars, and SqlBinary work). This will alleviate the problem for those using the Microsoft .NET Oracle provider without any explicit dependencies on the System.Data.OracleClient.