String.IsNullOrEmpty c# is not triggered

307 Views Asked by At

I am struggling to understand why the below code works perfectly well on a computer but not on another. Expected behaviour:

  • When currentUserSAMAccountName is null or empty String.IsNullOrEmpty matches and fill the Conf.OwnerUserName
  • When currentUserSAMAccountName is not null it goes it displays "Current user is:"

Can anyone offer me a second pair of eyes looking at code?

public static Conference GetUpdateConference(this Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem, string currentUserSAMAccountName) 
{
  // ...
  if (String.IsNullOrEmpty(currentUserSAMAccountName))
    Conf.OwnerUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
  else {
    Console.Write("Current user is: " + currentUserSAMAccountName + ".");
    // ...
  }
}

// Call of the function with this.currentOnbehalfUser that might be null or not initialised.
Item.GetUpdateConference(this.currentOnbehalfUser?.GetSAMAccountName());

// result is Current user is: . // No space 

I have check the following references:

  1. Use of documentation of the Null-conditional operators: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-
  2. Similar post :
0

There are 0 best solutions below