运行代码从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'.
这是我的相同代码:
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],
在ExecuteSqlCommand行上获取错误。
从错误消息中可以明显看出,您拥有Oracle.ManagedDataAccess的两个不同的副本,版本4.122.1.0和4.122.18.3,这两个arent兼容的类型只是因为它们看起来相同。 您应该尝试弄清楚您要使用哪个版本,以及另一个版本来自何处,并且至少在代码的这一部分中,请确保仅使用该程序集的一个版本。
上述解决方案有效。 @ LasseV&gstherKarlsen
您需要的所有详细信息都在错误消息中,这是经过简化和强调的版本:
[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)
因此,这里的问题是您有两个不同的Oracle.ManagedDataAccess副本和版本,并且您在它们之间混合使用类型。
类型的完全限定名称不仅是文本名称,还包含包含该名称的程序集的完整版本和签名,因此即使两种类型在源代码方面甚至是编译方面都是100%相同的, 它们来自组件的两个不同版本的事实使它们不兼容。
您需要做的是弄清楚引用两个程序集的位置,找出要使用的程序集,然后更正其他引用,以使它们都引用程序集的相同版本。
那应该使错误消失。