This is a migrated thread and some comments may be shown as answers.

Unable to cast object of type 'Oracle.DataAccess.Client.OracleParameter' to type 'Oracle.ManagedDataAccess.Client.OracleParameter'.

6 Answers 3982 Views
Databases and Data Types
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anthony
Top achievements
Rank 1
Anthony asked on 25 Jul 2014, 03:02 PM
Hi Telerik Forum,

Please could someone help me in the right direction, I seem to be missing something simple but I keep running into the following error:

An unhandled exception of type 'System.InvalidCastException' occurred in Oracle.ManagedDataAccess.dll

Additional information: Unable to cast object of type 'Oracle.DataAccess.Client.OracleParameter' to type 'Oracle.ManagedDataAccess.Client.OracleParameter'.


I am using Oracle XE 11g Release 2 with a test stored procedure which returns a ref cursor. When I add the stored procedure to the entities model and create the domain method it generates the following in the EntitiesModel.cs:

01.public IEnumerable<BOOK> SPSINGLEREFCUR()
02.        {
03.            // Oracle.DataAccess assembly reference is required
04.            Oracle.DataAccess.Client.OracleParameter parameterBOOKSCUR = new Oracle.DataAccess.Client.OracleParameter();
05.            parameterBOOKSCUR.ParameterName = "BOOKSCUR";
06.            parameterBOOKSCUR.OracleDbType = Oracle.DataAccess.Client.OracleDbType.RefCursor;
07.            parameterBOOKSCUR.Direction = ParameterDirection.Output;
08. 
09.            IEnumerable<BOOK> queryResult = this.ExecuteQuery<BOOK>("\"SYSTEM\".\"SPSINGLEREFCUR\"", CommandType.StoredProcedure, parameterBOOKSCUR);
10.         
11.         
12.            return queryResult;
13.        }


I've downloaded and installed the following ODP.NET: ODAC 12c Release 2 and Oracle Developer Tools for Visual Studio (12.1.0.1.2)  [Released December 20, 2013]

And have looked at http://docs.telerik.com/data-access/developers-guide/database-specifics/oracle/data-access-tasks-consume-oracle-managed-driver for any guidenance but no such luck.

I did not see any mention of using different assemblies or changing any settings and strikes me as strange that the OracleParameter is forcifully created as Oracle.DataAccess.Client.OracleParameter.

Any help would be greatly appreciated!

6 Answers, 1 is accepted

Sort by
0
Accepted
Ralph Waldenmaier
Telerik team
answered on 28 Jul 2014, 11:41 AM
Hi Trevor,
Thank you for sharing your details.
In your case, you have specified to use the Oracle managed driver. Though, because you can only specify Oracle as the backend, we are generating the code based on the 'regular' Oracle driver as you can see in the generated script.
In order to get this working, you need to copy this method to a separate partial class of your context and change the parameter definition to use the 'Oracle.ManagedDataAccess.Client.OracleParameter' instead of the generated one. By doing this, you are matching the parameter version with the loaded assembly.

In case you want to work with the unmanaged Oracle driver, you can simply change the provider name in your configuration.

I hope this information is helpful for you.
Feel free to ask in case you have any other question.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Anthony
Top achievements
Rank 1
answered on 28 Jul 2014, 12:03 PM
Hi Ralph,

Thank you very much for getting back to me! That explains it!

I've changed my provider name and that got things going correctly again. If the managed drivers become required I'll implement your suggestion.

Thank you again.
Trevor
0
Don
Top achievements
Rank 1
answered on 05 Nov 2014, 06:38 PM
I am having the same issue but I am new to oracle so i have no idea how to fix this.
I was following this example and it does not work. http://docs.telerik.com/data-access/developers-guide/database-specifics/oracle/data-access-tasks-oracle-execute-sp-result-set

Please provide more detail how to fix this.
0
Don
Top achievements
Rank 1
answered on 05 Nov 2014, 06:39 PM
I am having the same issue but I am new to oracle so i have no idea how to fix this.
I was following this example and it does not work.

http://docs.telerik.com/data-access/developers-guide/database-specifics/oracle/data-access-tasks-oracle-execute-sp-result-set

Please provide more detail how to fix this.
0
Ralph Waldenmaier
Telerik team
answered on 06 Nov 2014, 03:24 PM
Hello Dorothy,
When working with the Oracle managed drivers, you need to also reference the types from the Oracle managed assembly. Basically when following the example from the documentation, then changing the using should do the trick. See the following snippet:

using Oracle.DataAccess.Client;

Hope this helps.
Do come back in case you need further assistance.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
0
Ralph Waldenmaier
Telerik team
answered on 06 Nov 2014, 03:32 PM
Hi Dorothy,
Hitting the send button to quickly is never a good idea. The snippet should be the following:

using Oracle.ManagedDataAccess.Client;

This should be it.

Regards,
Ralph Waldenmaier
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Databases and Data Types
Asked by
Anthony
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Anthony
Top achievements
Rank 1
Don
Top achievements
Rank 1
Share this question
or