运行代码从Oracle DB获取数据时出现以下错误。


  [A] Oracle.ManagedDataAccess.Client.OracleParameter无法强制转换为
  [B] Oracle.ManagedDataAccess.Client.OracleParameter。 A型起源
  来自'Oracle.ManagedDataAccess,Version = 4.122.18.3,Culture = neutral,
  位置“ LoadFrom”中的PublicKeyToken = 89b483f429c47342”
  'd:\ Users \ mukadfar \ AppData \ Local \ Temp \ Temporary ASP.NET
  文件\ vs \ 02d43168 \ 78988466 \ assembly \ dl3 \ 95159e45 \ 00d2c436_a83bd401 \ Oracle.ManagedDataAccess.dll'。
  类型B源自“ Oracle.ManagedDataAccess,版本= 4.122.1.0,
  文化=中性,PublicKeyToken = 89b483f429c47342'在上下文中
  位置'd:\ Users \ mukadfar \ AppData \ Local \ Temp \ Temporary中的'Default'
  ASP.NET
  文件\ 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行上获取错误。

最佳答案

您需要的所有详细信息都在错误消息中,这是经过简化和强调的版本:


  无法将[A] Oracle.ManagedDataAccess.Client.OracleParameter强制转换为[B] Oracle.ManagedDataAccess.Client.OracleParameter。类型A源自'Oracle.ManagedDataAccess,Version = 4.122.18.3,(剪一些文本)类型B来自'Oracle.ManagedDataAccess,Version = 4.122.1.0,Culture = neutral,(剪断)


因此,这里的问题是您有两个不同的Oracle.ManagedDataAccess副本和版本,并且您在它们之间混合使用类型。

类型的完全限定名称不仅是文本名称,还包含包含该名称的程序集的完整版本和签名,因此即使这两种类型在源代码方面,甚至在编译方面都是100%相同的,它们来自组件的两个不同版本的事实使它们不兼容。

您要做的就是找出两个程序集的引用位置,找出您要使用的程序集,然后更正其他引用,以使它们都引用同一版本的程序集。

那应该使错误消失。

关于c# - [A] Oracle.ManagedDataAccess.Client.OracleParameter无法转换为[B] Oracle.ManagedDataAccess.Client.OracleParameter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52379587/

10-12 01:24