4

I modified a workflow in TFS template, in the head of this workflow I initialized an array of string named NextChainBuildDefinition. After a few steps, I tried to check if this array is null or not.

I did this way:

String.IsNullOrEmpty(CStr(NextChainBuildDefinition.Count))

After this I see error: Exception Message: Value cannot be null. Therefore NextChainBuildDefinition is null, and in that step it throws an exception.

How do I check if this string array is null?

2 Answers 2

7

You need to check if the array itself is null or empty - your current code is checking if the string conversion of the number of elements in the array is empty - this isn't going to work at all.

Instead, you need to do a two step check - both for if the array itself is null, and if not, if it's empty:

If (NextChainBuildDefinition IsNot Nothing AndAlso NextChainBuildDefinition.Count > 0) Then
  'Array has contents
Else
  'Array is null or empty
End if
Sign up to request clarification or add additional context in comments.

Comments

1

Why not just test ubound() of the array? old question, i know.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.