InvalidCastException

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
Thomas Hoekstra
Posts: 9
Joined: Wed 02 Apr 2008 13:35

InvalidCastException

Post by Thomas Hoekstra » Tue 31 Aug 2010 14:54

Hi,

when I try to get the value of an attribute on an OracleObejct, an InvalidCastException is thrown.

This happens, when
1. the DataType is NUMBER
2. and the attribute is not initialized (the value is NULL on the Oracle side)

I have just updated from 4.75 to the most recent version, and before the update this exception was not thrown.

Is there a way to avoid the exception, e.g. by checking for a NULL value before accessing the attribute?
##### EDIT #########

This only happens, when the indexer with the attribute-name is used.

GetOracleValue returns a double (0.0) instead of an OracleNumber with the IsNull property set to true.

So, there is a way to avoid the exception, but I still think the behavior is not correct.

##################

Kind regards,


Thomas Hoekstra

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 01 Sep 2010 14:04

Could you please specify how exactly you are retrieving this attribute? For example, the following line returns an object of the System.DBNull type:

Code: Select all

object obj = MyOracleObject["number1"];
I've used the following object type:

Code: Select all

CREATE OR REPLACE TYPE MY_OBJECT AS OBJECT (
    ID NUMBER(38),
    VALUE1 VARCHAR2(20),
    NUMBER1 NUMBER(38)
)
Also, what versions of dotConnect for Oracle (speaking about the latest one, do you mean the Beta 6.0.10 build or the latest release 5.70.152 version?) and Oracle server are you using?

Thomas Hoekstra
Posts: 9
Joined: Wed 02 Apr 2008 13:35

Post by Thomas Hoekstra » Wed 01 Sep 2010 14:52

The version I use is 5.70.152.0.

I'm using the index, just as you do:

Code: Select all

object obj = MyOracleObject["number1"];
In my case, the attribute of the oracle type is declared as FLOAT.
Also, this is an inherited attribute:

Code: Select all

create or replace type MY_PARENT_TYPE as object
(
  TestAttribute FLOAT  
)
/
create or replace type MY_TYPE under MY_PARENT_TYPE
(
  SecondAttribute DATE;  
)
/
But it does not return System.DBNull and instead an InvalidCastException is thrown.

What about the second issue? Why does GetOracleValue() return 0.0?
I would expect an OracleNumber object with the IsNull property set to true.

Any ideas?

BTW: I still have the old CoreLab.Oracle assemblies installed on my machine, but I don't reference them in this project.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 02 Sep 2010 09:49

Thank you for your assistance, we've reproduced the issue in the case of inherited types. We will investigate it and inform you about the results.

As for the GetOracleValue method, in our environment it returns System.DBNull in the case of null at the server side. Could you please specify the version of the Oracle server you are using so that we are able to reproduce the issue?

The designed behaviour for GetOracleValue is to return either double or DBNull for FLOAT database fields. We do not plan to change this behaviour as this would affect the compatibility with prior versions.

Concerning the CoreLab assemblies, they should not influence the applications using dotConnect for Oracle.

Thomas Hoekstra
Posts: 9
Joined: Wed 02 Apr 2008 13:35

Database Version

Post by Thomas Hoekstra » Thu 02 Sep 2010 10:04

Hi,

my Database is 11.1.0.6 64 Bit Standard Edition One on Windows Server 2008 R2.

Regarding the GetOracleValue method: that's no problem. I was just pointing out what I would expect.

I'm no longer using the indexer in my project, instead I use GetOracleValue now. So, I don't rely on a patch. Anyway... good to hear you could reproduce the issue.

Thanks,

Thomas Hoekstra

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 03 Sep 2010 16:49

Could you please specify the version of Oracle client you are using, and the way you are receiving OracleObject from the database? We couldn't reproduce the issue with GetOracleValue returning zero instead of DBNull.

Also, we've fixed the issue with attributes, the fix will be available in the nearest build.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 24 Sep 2010 16:44

We've released the 5.70.170 build of dotConnect for Oracle. It contains the fix for the issue with attributes of the inherited type. The build can be downloaded from
http://www.devart.com/dotconnect/oracle/download.html
(the trial version) or from Registered Users' Area (provided that you have an active subscription):
http://secure.devart.com/

The detailed information about the fixes and improvements implemented in dotConnect for Oracle 5.70.170 is available at
http://www.devart.com/forums/viewtopic.php?t=19068

Post Reply