io_TransactionItem.SpecificContent("Name").ToString <> ""
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…
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?
Well the Best Practice would be to follow C option.
Can you point out your reasoning or docs that would suggest it do it in C way?
I would go for combination like this one:
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.
Cool, also… didn’t know about AndAlso
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)
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:
io_TransactionItem.SpecificContent.Any(Function(x) x.Key = “Accounts” AndAlso x.Value IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(x.Value.ToString))
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.
This last expression should check it all at once, right?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.