Reputation: 470
I'm the below error while running my code to get data from Oracle DB.
[A]Oracle.ManagedDataAccess.Client.OracleParameter cannot be cast to [B]Oracle.ManagedDataAccess.Client.OracleParameter. Type A originates from 'Oracle.ManagedDataAccess, Version=4.122.18.3, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'LoadFrom' at location 'd:\Users\mukadfar\AppData\Local\Temp\Temporary ASP.NET Files\vs\02d43168\78988466\assembly\dl3\95159e45\00d2c436_a83bd401\Oracle.ManagedDataAccess.dll'. Type B originates from 'Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' in the context 'Default' at location 'd:\Users\mukadfar\AppData\Local\Temp\Temporary ASP.NET Files\vs\02d43168\78988466\assembly\dl3\0b972c52\00ac59cd_7dd5d201\Oracle.ManagedDataAccess.dll'.
Here is my code for the same:
var param1 = "K60";
var param2 = "2018.09.14";
var param3 = "2018.09.14";
var param4 = string.Empty;
var param5 = string.Empty;
var param6 = string.Empty;
var param7 = string.Empty;
var param8 = string.Empty;
var param9 = string.Empty;
var param10 = string.Empty;
var param11 = string.Empty;
var param12 = string.Empty;
var param13 = string.Empty;
var param14 = string.Empty;
var param15 = string.Empty;
var param16 = string.Empty;
var param17 = string.Empty;
var param18 = string.Empty;
var parameters = new[]
{
new OracleParameter("wr_proccode_PM_cmb_C179", OracleDbType.Varchar2, 100, param1 != null ? (object)param1 : DBNull.Value, ParameterDirection.Input),
new OracleParameter("wr_start_day_C179", OracleDbType.Varchar2, 100, param2 != null ? (object)param2 : DBNull.Value, ParameterDirection.Input),
new OracleParameter("wr_end_day_C179", OracleDbType.Varchar2, 100, param1 != null ? (object)param3 : DBNull.Value, ParameterDirection.Input),
new OracleParameter("wr_operating_efficiency_total", OracleDbType.Decimal, 4000, param4 != null ? (object)param4 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_time_efficiency", OracleDbType.Decimal, 4000, param5 != null ? (object)param5 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_tons_efficiency_total", OracleDbType.Decimal, 4000, param6 != null ? (object)param6 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_pope_gross", OracleDbType.Decimal, 4000, param7 != null ? (object)param7 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_packed_net_prod", OracleDbType.Decimal, 4000, param8 != null ? (object)param8 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_bottom_waste", OracleDbType.Decimal, 4000, param9 != null ? (object)param9 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_avg_gm2", OracleDbType.Decimal, 4000, param10 != null ? (object)param10 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_unplanned_shutdown_pcs", OracleDbType.Int32, 4000, param11 != null ? (object)param11 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_grade_change_pcs", OracleDbType.Int32, 4000, param12 != null ? (object)param12 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_break_pcs", OracleDbType.Int32, 4000, param13 != null ? (object)param13 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_break_hr", OracleDbType.Varchar2, 4000, param14 != null ? (object)param14 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_unplanned_shutdown_hr", OracleDbType.Varchar2, 4000, param15 != null ? (object)param15 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_packed_net_prod_pcs", OracleDbType.Int32, 4000, param16 != null ? (object)param16 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_rewinder_net_prod_pcs", OracleDbType.Decimal, 4000, param17 != null ? (object)param17 : DBNull.Value, ParameterDirection.InputOutput),
new OracleParameter("wr_warehouse_post_waste", OracleDbType.Decimal, 4000, param18 != null ? (object)param18 : DBNull.Value, ParameterDirection.InputOutput)
};
var procedure = $"Begin TP_BALELINE.getNextPlannedObjects(:wr_proccode_PM_cmb_C179, :wr_start_day_C179, :wr_end_day_C179, :wr_operating_efficiency_total, :wr_time_efficiency, :wr_tons_efficiency_total, :wr_pope_gross, :wr_packed_net_prod, :wr_bottom_waste, :wr_avg_gm2, :wr_unplanned_shutdown_pcs, :wr_grade_change_pcs, :wr_break_pcs, :wr_break_hr, :wr_unplanned_shutdown_hr, :wr_packed_net_prod_pcs, :wr_rewinder_net_prod_pcs, :wr_warehouse_post_waste); END;";
this.databaseContext.ExecuteSqlCommand(
procedure,
parameters[0],
parameters[1],
parameters[2],
parameters[3],
parameters[4],
parameters[5],
parameters[6],
parameters[7],
parameters[8],
parameters[9],
parameters[10],
parameters[11],
parameters[12],
Getting the error on the line ExecuteSqlCommand.
Upvotes: 1
Views: 4478
Reputation: 2421
I had the same problem and in my case, I have two versions of Oracle.DataAccess.dll
In the project I'm working on, the migration to a higher framework version includes this dll. I don't have installed the 4.x
version, but rather, the 2.x
version on the GAC.
After trying changing the Web.config as follows:
<runtime>
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89b483f429c47342"/>
<bindingRedirect oldVersion="2.111.7.20" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
It loads the 4.x version, but, at the end of loading all the dlls, it keep loading the 2.x version from the GAC - overwriting the loaded 4.x
version.
I also tried changing the compilation settings from Any CPU
to x86
- as mentioned here, adding the 4.x
version on all parts where the dll is referenced, cleaning the IIS cache and temporal files, but, those attempts didn't worked for me.
Looking other answers - like this one - where mentions the installation in the GAC either with the installer or modifying the Registry, but I can't use any of those options - I'm working on a restrictive enviroment.
For avoid more problems, I had to add the 2.x
version on all parts where the dll is referenced and keep working with the loaded/installed version in the GAC and now, this issue no longer appears.
Side note: probably, the better option is installing the version you need in your enviroment and specifiyng the version you want to work in your project - if you have more than on version of the same dll(s).
Upvotes: 1
Reputation: 391336
All the details you need is in the error message, here's a shortened and emphasized version:
[A]Oracle.ManagedDataAccess.Client.OracleParameter cannot be cast to [B]Oracle.ManagedDataAccess.Client.OracleParameter. Type A originates from 'Oracle.ManagedDataAccess, Version=4.122.18.3, (snip some text) Type B originates from 'Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, (snip)
So the problem here is that you have two distinct copies and versions of Oracle.ManagedDataAccess
, and you're mixing types between them.
The fully qualified name of a type isn't just textual, it also contains the full version and signature of the assembly that contained it, so even though the two types might be 100% identical source-code wise, and even compiled-wise, the fact that they come from two different versions of the assembly makes them incompatible.
What you have to do is figure out where the two assemblies are referenced, figure out which one you want to use, and correct the other reference(s) so that they all refer to the same version of the assembly.
That should make the error go away.
Upvotes: 5