Runtime error- "Assign: Unable to cast object of type 'System.Double' to type 'System.String'.", when using List

I received the error - “Assign: Unable to cast object of type ‘System.Double’ to type ‘System.String’.”,…

expression throwing the exception:
inputFromExcelDT.AsEnumerable.Select(Function(row) row.Field(Of String)(“Discharge Date”)).toList

Looking at my workflow, and after running my workflow in debug mode, I still dont understand the cause of the error. I need some help.



Below is the full error log:

Message: Unable to cast object of type ‘System.Double’ to type ‘System.String’.

Exception Type: System.InvalidCastException

System.InvalidCastException: Unable to cast object of type ‘System.Double’ to type ‘System.String’. at System.Data.DataRowExtensions.UnboxT1.ReferenceField(Object value) at System.Data.DataRowExtensions.Field[T](DataRow row, String columnName) at lambda_method(Closure , DataRow ) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[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, IDictionary`2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

the field method is sensitive about the value / datatypes

You can change the linq to:

inputFromExcelDT.AsEnumerable().Select(Function (row) row("Discharge Date").toString().Trim() ).toList()

@ppr that works, thanks!

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