Object reference not set to an instance of an object error when assigning values from DataRow to Array of Strings

Hi guys, I have the following task at hand I need to get all the users and their pass and DB from a certain SQL DataBase and from there assign them to different arrays.

However the issue seems to be that some of the values in the “db” field appear to set to NULL and I get the below error:
“”“”
20.3.0-beta.84+Branch.release-v20.3.0.Sha.7fc79beda33f6ae9c6f407946cf052a16a3d7a0e

Source: Assign

Message: Object reference not set to an instance of an object.

Exception Type: System.NullReferenceException

RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , DataRow )
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Linq.Buffer1…ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(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.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
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)
“”"

Furthermore I changed the NULL values to 0 or null (with lowercase) and it stops giving me that message, however I am allowed to do this for debugging purposes so at production time I would not be able to mess around with the Data Base values.

So any advise how to add the NULL value to my array ? At the moment I am using an “Assign” activity to do this and the expression which I am using is “Users.AsEnumerable().Select(Function (a) a.Field(of string)(“db”).ToString).ToArray()”

Also on a side note is there a way to filter an array so it does not include certain users and assign that to a new array ?

Thank you very much

@boyanz35 The Assign Statement can be modified in this way :

yourArrayVar = if(Users.AsEnumerable().Select(Function (a) a.Field(of string)(“db”).ToString).ToArray().Count>0,Users.AsEnumerable().Select(Function (a) a.Field(of string)(“db”).ToString).ToArray(),Nothing)

Can you try with this Expression

No sorry it gives the absolute same error message

@boyanz35 Can you try this instead :

yourArrayVar = Users.AsEnumerable().Select(Function (a) if(String.IsNullorEmpty(a(“db”).ToString) or String.IsNullOrWhiteSpace(a(“db”).ToString),“Null”,a(“db”).ToString)).ToArray()

1 Like

Awesome it works like a charm, thank you a lot ! <3

1 Like

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