I know this may sound like a very stupid question, but I have no answers to this question. One of our users recently reported an error, and I realized that the old code bit used != string.Empty
, not IsNullOrEmpty()
. I fixed it with IsNullOrEmpty()
and now it works fine, but I would like to understand the problem
The fact is that the same bit of code works differently on certain machines. I basically have an object: context["MODE"]
, which should be empty. I have added some tests for this:
contextBuilder.AppendLine("MODE: |" + context["MODE"] + "|"); contextBuilder.AppendLine("MODE != string.Empty: " + (context["MODE"] != string.Empty)); contextBuilder.AppendLine("MODE TRIM != string.Empty: " + (context["MODE"].ToString().Trim() != string.Empty)); contextBuilder.AppendLine("MODE.IsNullOrEmpty: " + string.IsNullOrEmpty(context["MODE"].ToString())); contextBuilder.AppendLine("MODE.TRIM.IsNullOrEmpty: " + string.IsNullOrEmpty(context["MODE"].ToString().Trim()));
Here are my logs about the details of this field:
MODE: || MODE != string.Empty: False MODE TRIM != string.Empty: False MODE.IsNullOrEmpty: True MODE.TRIM.IsNullOrEmpty: True
Here are his magazines:
MODE: || MODE != string.Empty: True MODE TRIM != string.Empty: False MODE.IsNullOrEmpty: True MODE.TRIM.IsNullOrEmpty: True
As you can see, there is one difference: MODE != string.Empty
is a lie for me (it makes sense), true for him! MODE is obviously not null (otherwise .ToString()
failed). The problem with using IsNullOrEmpty has been fixed, but I'm trying to find out why this does not work on certain user machines and not on others. Usually some of us had no problems with my trials, others were.
I really don't understand what I can find out about this. Why is its mode different from zero and String.Empty
, but IsNullOrEmpty
returns true? Also note that cropping is actually String.Empty
also
Thanks!
source share