C# System.InvalidCastException:对象不能存储在此类型的数组中。在C中
当使用setter为下面提到的对象赋值时,我得到了下面的错误。这是我的密码C# System.InvalidCastException:对象不能存储在此类型的数组中。在C中,c#,.net,C#,.net,当使用setter为下面提到的对象赋值时,我得到了下面的错误。这是我的密码 public override void Execute(OrderedDictionary htFileList) { mlogger.Error("RemoveRestrictions start.."); string htFile = (string) htFileList[(object) "connection_id"]; try { string str = "sele
public override void Execute(OrderedDictionary htFileList)
{
mlogger.Error("RemoveRestrictions start..");
string htFile = (string) htFileList[(object) "connection_id"];
try
{
string str = "select distinct I.[Security Id] AS [sec_id] FROM IVPSecMasterVendor.dbo.vw_MSCIRestritionList_MSCIRestrictionFeed_EquityCommonStock F RIGHT OUTER JOIN IVPSecMaster.dbo.vwCommonAttributes I ON I.isin = F.ISIN WHERE I.[Security Id] like 'EQST%' and F.ISIN IS NULL; select TD.display_name from IVPSecMaster.dbo.ivp_secm_attribute_details AD JOIN IVPSecMaster.dbo.ivp_secm_template_details TD ON TD.attribute_id = AD.attribute_id where sectype_table_id = 20 and to_show = 1";
SqlConnection sqlConnection = new SqlConnection();
DataSet dataSet = new DataSet();
SqlCommand selectCommand = new SqlCommand();
sqlConnection.ConnectionString = htFile;
selectCommand.Connection = sqlConnection;
selectCommand.CommandText = str;
new SqlDataAdapter(selectCommand).Fill(dataSet);
mlogger.Error("Query Output[0] is"+dataSet.Tables[0].Rows.Count);
SecMMultiInfoValues mmultiInfoValues1 = new SecMMultiInfoValues();
mlogger.Error("mmultiInfoValues1 created");
if (dataSet == null || dataSet.Tables.Count <= 1 || dataSet.Tables[0].Rows.Count <= 0 || dataSet.Tables[1].Rows.Count <= 0)
return;
string[][] array = dataSet.Tables[1].AsEnumerable().Select<DataRow, string[]>((Func<DataRow, string[]>) (x => new string[2]{ x.Field<string>("display_name"), "" })).ToArray<string[]>();
mlogger.Error("Dataset stored into array : string[][] array");
foreach(string[] arr in array)
{
foreach(string stri in arr)
{
mlogger.Error(" stri "+stri);
}
}
SecMMultiInfoValues mmultiInfoValues2 = new SecMMultiInfoValues();
mmultiInfoValues2.AttributeValues = new string[2][];
mmultiInfoValues2.AttributeValues.SetValue((String[][])array, 0);
mlogger.Error("mmultiInfoValues2 created");
mlogger.Error("Set values for mmultiInfoValues2");
SecMMultiInfoValues mmultiInfoValues3 = mmultiInfoValues2;
mlogger.Error("mmultiInfoValues3 created");
ThirdPartyUpdateService partyUpdateService = new ThirdPartyUpdateService();
mlogger.Error("partyUpdateService created");
foreach (DataRow row in (InternalDataCollectionBase) dataSet.Tables[0].Rows)
{
mlogger.Error("fetching secm record");
SecMRecord secMrecord = partyUpdateService.UpdateMultiInfoOn("SYSTEM", "Equity Common Stock - MSCI Restrictions", "Security ID", row["sec_id"].ToString(),"", "", "", "", new SecMMultiInfoValues[1]{ mmultiInfoValues3 });
mlogger.Error("secMrecord.Name : "+secMrecord.Name);
if (!secMrecord.IsSuccess)
{
EventLog.WriteEntry("Application", secMrecord.Name);
mlogger.Error("Failed" + secMrecord.Name);
}
}
}
catch (FileNotFoundException ex)
{
EventLog.WriteEntry("Application", ex.ToString());
mlogger.Error("Exception" + ex.ToString());
throw ex;
}
catch (ArgumentNullException ex)
{
throw ex;
}
catch (ArgumentOutOfRangeException ex)
{
throw ex;
}
catch (IOException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
mlogger.Error("RemoveRestrictions End..");
}
我在排队时遇到了这个例外
mmultiInfoValues2.AttributeValue.SetValueString[]数组,0;:。请帮忙 变量是字符串数组的数组。您试图将其中一个数组的值设置为字符串数组数组,而不是单个字符串数组,这是无效的。从语法上讲,你可以做:
mmultiInfoValues2.AttributeValues = array;
但如果不知道设置AttributeValue的具体用途,就不清楚这是否能实现您想要的效果。也许您需要将数组从array复制到mmultiInfoValues2,而不仅仅是更改引用。嘿,我认为AttributeValues只是一个二维字符串变量。请参见->公共字符串[][]属性值{get;set;}好吧,这是一个数组数组,与二维数组有些不同,但是您试图将一个应该是字符串数组的值设置为另一个锯齿数组,这就是为什么会出现错误的原因。如果您可以将其减少为。目前很难说问题出在哪里。