Cannot assign from type 'System.Object' to type 'System.Data.DataTable' in Assign activity '

Hi Team,

I am getting error Cannot assign from type ‘System.Object’ to type ‘System.Data.DataTable’ in Assign activity I am using linq query to filter table and there is no error in the query.

When i created a new data table variable then the error was not showing and if i modified the query again the error message was the same.

Hi @Mohan_Reddy

Please delete the activity and reinitialize it again. It will solve the error. As we are getting these errors in the latest Studio updates.

Regards

@Mohan_Reddy

Try by remove the value in the assign and rewrite it.

Hope it helps!!

In such cases we help the compiler, by fine tuning the select

(From d in dtData.AsEnumerable
Where …
Select r = d).CopyToDataTable

Thank for your suggestions @Parvathy & @pravallikapaluri ,

I have tried both the suggestions but the error persists.

Hi @Mohan_Reddy

May be the written query has some error. Try fixing that error.

Regards

Hi

Following is my Query, can you let me know where to modify it.

(
From r In dt_InputData
Where r(“Order Category”).ToString= “dineout”
Select r
).CopyToDataTable

Hi @Mohan_Reddy

Try this:

(
From r In dt_InputData
Where r("Order Category").ToString.Trim().Equals("dineout")
Select r
).CopyToDataTable()

Hope it helps!!

as mentioned within the bold parts:


(From d In dt_InputData.AsEnumerable
Where d("Order Category").ToString.Trim.Equals("dineout")
Select r = d).CopyToDataTable

never omit the AsEnumerable when writing LINQ statements dealing with datatables

Hi @ppr ,

I have copied and replaced it with a new code still it is showing an error.

As verified below it is compiling:

ensure the variable are created correctly, within the needed scope and not dupicated within different scopes.

We also do practice:

  • when a correct working statement is not accepted by compiler
  • delete the assign right side
  • save XAML
  • retype the same and correct statement

Due to some cache issues we encountered that corrections can sometimes hang

a correct working statement

ensure that it is correct and keep in mind

Hi @ppr ,

I have tried all the ways (System restart & create a new process) but the error persists.
Today only my studio was updated to the 2024.2 version

I observed that in one of my colleagues systems, the query is working fine and i found that his studio version was 2023.13

can you share with us the used Package Versions?
we are much interested on the UiPath.System.Activities Package version. Feel free to downgrade it to a 23.10.X Level

Hi @ppr

UiPath.System.Activities package version: 23.10.2

thanks for the feedback. We would assume that a 23.10.2 vs 23.10.5 will not make a change. Sucg LINQ we already used since 2018/2019

However, when the Correct statement is blamed by the compiler:

  • we can try by remodellings / cache forcings to get it accepted

When the issue comes from Studio Version 2024.2 then maybe some one else from the community could replicate at their end and let us know the result.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.