string.IsNullOrEmpty returns true when supplied string is not null

后端 未结 3 1028
日久生厌
日久生厌 2021-01-12 18:05

I have a unit test that calls a method on an object passing in a string.

One of the first things that the method being called does is to check the string for null or

3条回答
  •  清歌不尽
    2021-01-12 18:40

    I'm also experiencing this in Visual Basic with If String.IsNullOrEmpty(foo). I agree with Andrei's comment, this seems to be a bug with how the debugger is visualizing this particular construct.

    Clean/Rebuild did not affect it. Interestingly, if you add a more complex body to your If statement, the debugger will only pause (i.e. yellow arrow) on the last line of the body. It does not actually execute the line of code.

    It would be interesting if someone could gives us some insight as to why this happens.

    Here is the code where I'm seeing this:

    enter image description here

    Notice the debugger arrow is on the line e.Cancel = True, even though myItem.Subject is not null. When I press F10, the arrow will advanced to the ElseIf statement and e.Cancel will still be False.

    Also, while the debugger is on this line, I cannot drag the arrow to a different line like I usually can. If I attempt to move to another line by dragging the yellow arrow, I get the following error:

    enter image description here

提交回复
热议问题