Invoke c# code. Error: Object doesn't contain definition of toString

Hi Guys,
I faced the issue while using invoke C# code.
I receive an Error:

while trying to invoke this code:
for (int i = 20; i < inputDt.Rows.Count; i++)
for (int j = 1; j < inputDt.Columns.Count; j++)
if (!String.IsNullOrEmpty(inputDt.Rows[i][j].toString()) && inputDt.Rows[i][j] != “0”)
System.Data.DataRow dr = null;
dr = outputDt.NewRow();
dr[0] = inputDt.Rows[0][j];
dr[1] = inputDt.Rows[1][j];
dr[2] = inputDt.Rows[i][0];
dr[5] = inputDt.Rows[i][j];


The list of arguments is:

Any idea why it causes and how can be resolved?

instead of !String.IsNullOrEmpty(inputDt.Rows[i][j].toString()
made inputDt.Rows[i][j]!=DBNull.Value

1 Like

Ultimately, I don’t receive and error. But i get wrong results. So I need compare the cell values as a String.
Why Invoke code doesn’t work with .toString ??? Anyone knows?

Try doing this -

Create your own new string ad hoc in the loop this way -



Normally C# the type conversion of ToString should always be followed by “()” it is very strict about that. :slight_smile:

1 Like

Do u mean escape from using Invoke and to do everything in ad hoc loops?

Well TBH I have faced issues when using C# code in invoke code, either go with VB or you can use the inbuilt loops for this purpose. It will be more readable for people who are maintaining your code.

1 Like

Once I tried

i received : cannot convert object ot string.
Then I added inputDt.Rows[i][j].toString - and received “cannot implicitly convert object to string”.

So you are right. Other way to do this should be made up. Invoke code activity is not good enough if doesnt work with toString…