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

7 posts, 1 answers
  1. Trevor
    Trevor avatar
    15 posts
    Member since:
    Apr 2014

    Posted 25 Jul 2014 Link to this post

    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!
  2. Answer
    Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 28 Jul 2014 Link to this post

    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.
     
  3. DevCraft banner
  4. Trevor
    Trevor avatar
    15 posts
    Member since:
    Apr 2014

    Posted 28 Jul 2014 in reply to Ralph Waldenmaier Link to this post

    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
  5. Don
    Don avatar
    2 posts
    Member since:
    Oct 2010

    Posted 05 Nov 2014 in reply to Ralph Waldenmaier Link to this post

    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.
  6. Don
    Don avatar
    2 posts
    Member since:
    Oct 2010

    Posted 05 Nov 2014 Link to this post

    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.
  7. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 06 Nov 2014 Link to this post

    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.
     
  8. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 06 Nov 2014 Link to this post

    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.
     
Back to Top
DevCraft banner