I have the following code, which results in a Null reference error. This works well outside (e.g. in Visual Studio) but not in UiPath. Any ideas where i am doing it wrong ? Here is the error and code:
Error
System.NullReferenceException: Object reference not set to an instance of an object.
at UiPathCodeRunner_e44525bcc724414497acade96d68e114.Run(Dictionary2& emailDict, String str, List1 lst)
Object reference not set to an instance of an object.
Dim item, key, val As String
Try
For Each item In lst 'lst is a list passed as input
key = item.Split(CChar(":"))(0).ToString.Trim
val = item.Split(CChar(":"))(1).ToString.Trim
emailDict.Add(key, val) 'dictionary defined as an out argument within UiPath
Next
Catch e As Exception
console.WriteLine(e)
console.WriteLine(e.Message)
console.WriteLine(e.Source)
End Try
Dim dictionary As New Dictionary (Of String, String)
Dim item, key, val As String
Try
For Each item In lst 'lst is a list passed as input
key = item.Split(CChar(":"))(0).ToString.Trim
val = item.Split(CChar(":"))(1).ToString.Trim
emailDict.Add(key, val)
Next
Catch e As Exception
console.WriteLine(e)
console.WriteLine(e.Message)
console.WriteLine(e.Source)
End Try
In UiPath you have to create a new dictionary variable inside invoke code and assign that dictionary to your output dictionary variable.
Try this,
Dim dict As New Dictionary (Of String, String)
Dim item, key, val As String
Try
For Each item In lst 'lst is a list passed as input
key = item.Split(CChar(“:”))(0).ToString.Trim
val = item.Split(CChar(“:”))(1).ToString.Trim
dict.Add(key, val)