I have a problem with the development of an application. I am using the eBay API to get information about the items a seller has listed. The Call I use is named "GetSellerList".
The response might contain a value called "CategoryID" (FreeAddedCategory.CategoryID) if there is a FreeAddedCategory available for the item. You would find a XML like this as response:
<ItemArray>
  <Item>
    <FreeAddedCategory>
      <CategoryID>XXXXXXXXX</CategoryID>
    </FreeAddedCategory>
  </Item>
</ItemArray>
Because this value is not always returned I am getting the following error message:
Object reference not set to an instance of an object
I now want to check if this object is available before using it to prevent getting the error. This is how I startet to solve the issue (but without success):
    foreach (ItemType item in apiCall.ApiResponse.ItemArray)
       {
          if (String.IsNullOrWhiteSpace(item.FreeAddedCategory.CategoryID))
                {
                    Console.WriteLine("FreeAdded: Nicht vorhanden!");
                }
        }
But also this check brings up the same error message. What can I do to make the code working? The logic should be like that:
IF item.FreeAddedCategory.CategoryID exist
  {
      do everything that needs to be done
  }
ELSE skip;
 
     
    