Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string.IsNullOrEmpty returns true when supplied string is not null

Tags:

c#

.net-4.5

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 empty.

However, no matter what the value of filePath is, the call to string.IsNullOrEmpty is true. See image below.

Why is string null or empty

Am I missing something here?

EDIT:

Checking for null and string.Empty separately works as expected:

enter image description here

EDIT 2:

I have cleaned the solution, deleted the bin directory via the file system and still, after a rebuild, the debugger shows that the ArgumentNullException should be being thrown, although it actually is not being thrown.

like image 798
Maciej Avatar asked Jun 17 '13 14:06

Maciej


1 Answers

The contents of filePath are definitely not null (and not empty), so that leaves us with two options:

  • You have a wider scope variable (i.e. global variable) named filePath, which is empty on null
  • Your debugger is referencing an older version of the binaries. In that case, claear and rebuild the solution

Update

Your question update makes me think the second option (of the above) is the one

like image 176
Adriano Carneiro Avatar answered Nov 01 '22 12:11

Adriano Carneiro