A. Not String.IsNullOrEmpty(io_TransactionItem.SpecificContent("Name").ToString)
B. io_TransactionItem.SpecificContent("Name").ToString <> ""
C.o_TransactionItem.SpecificContent("Name").Equals(Nothing)
Checking with these methods works in most cases but sometimes I still get with all of them an exception:
An exception has occurred: Object reference not set to an instance of an object. at Source: If Account
In the If account I check if I have set an element there, in this particular case I’m using C, but got the same for the rest as well…
io_TransactionItem.SpecificContent.ContainsKey("Name").ToString
Just checking for the key works but I would like to see if it is set or the key exists only if it is not empty?
What do you suggest for a best practice on checking content of a QueueItem?
tra.SpecificContent.Keys.ContainsKey("Condition") AndAlso Not String.IsNullOrWhiteSpace(tra.SpecificContent("Condition").ToString)
As with the first condition you check if the key exist, if does, it then checks if the value is filled.
Otherwise, it will return false (even by only checking the first statement.
I’m using an if as you proposed: io_TransactionItem.SpecificContent.ContainsKey("Accounts") AndAlso Not String.IsNullOrWhiteSpace(io_TransactionItem.SpecificContent("Accounts").ToString)
But this gives sometimes, pretty often this exception:
An exception has occurred: Object reference not set to an instance of an object.
I separated these two conditions to successive log messages and there is a case when the first validates to true and the second gives the above mentioned exception. The same exception is triggered if I just simply try to get io_TransactionItem.SpecificContent("Accounts").ToString. So this checking mechanism still should be fine tuned … Any ideas on how to?
Can you try this type of thing and see if it handles it?
If io_TransactionItem.SpecificContent.ContainsKey("Accounts") Then
assign strContent = If(io_TransactionItem.SpecificContent("Accounts") Is Nothing, "", io_TransactionItem.SpecificContent("Accounts"))
assign boolEmpty = String.IsNullOrWhiteSpace(io_TransactionItem.SpecificContent("Accounts").ToString)
End If
The dictionary may have but containing a null value, which is making the .toString fail.
Actually maybe be best to go with this type of Linq:
Yes, checking also for Nothing ends the circle… a bit cumbersome to have 3 checks for value check but understandable… Maybe there should be an activity to Retrieve a Queue item to which variables can be imported as outputs that are filled if their given key exists.