Error while executing LINQ to convert a row in DataTable to an Array

CopyJustOneColOfExcel.xaml (32.0 KB)
I am getting this error when I executed my workflow :

Assign - arrProjDef: Object reference not set to an instance of an object.

Here are the steps performed in my workflow which is attached above:

  1. Read from an Excel that has the following columns:
  2. Using the following activity:
    image
  3. Get just one column and transform it to an array using the following LINQ statement:
dtJustOneColumn.AsEnumerable().Select(Function(a) a.Field(of string)("Project").ToString).ToArray()

I am getting this error message:

System.NullReferenceException: Object reference not set to an instance of an object. at Namespace_c3f7.CopyJustOneColOfExcel_Expressions.CopyJustOneColOfExcel_Expressions_TypedDataContext4_ForReadOnly._Closure$__._Lambda$__15-0(DataRow a)
at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source)
at Namespace_c3f7.CopyJustOneColOfExcel_Expressions.CopyJustOneColOfExcel_Expressions_TypedDataContext4_ForReadOnly.__Expr2Get()
at Namespace_c3f7.CopyJustOneColOfExcel_Expressions.CopyJustOneColOfExcel_Expressions_TypedDataContext4_ForReadOnly.ValueType___Expr2Get()
at Namespace_c3f7.CopyJustOneColOfExcel_Expressions.InvokeExpression(Int32 expressionId, IList1 locations, ActivityContext activityContext) at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

I have checked the column name and it seems to be okay, I have even changed the column name yet I see the same error when I execute this LINQ statement.

Kindly help.
Thanks.

Hi,

Can you try either of the following?

dtJustOneColumn.AsEnumerable().Select(Function(a) a.Field(Of String)("Project")).ToArray()

OR

dtJustOneColumn.AsEnumerable().Select(Function(a) a("Project").ToString).ToArray()

Regards,

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