How to validate Generic list is null or empty

Installer(.exe or .msi):

License type(Free, Trial/License code):Free

Studio/Robot version:2019.6.0

Current behavior: Error Message Value Cannot be Null

Screenshot:

i’m trying to read list of unread messages using outlook mail activity and storing the attachment names in List of Strings (lstattachment) , certain times mail may not have attachments that time when i try to read the lstattachment.Any() it throws error message Value cannot be null , how do i check lstattachment is null or empty , i hope empty can be checked using listattachment.count > 0

logics i tried :

1 ) Nothing <> lstattachment
2) IsNotNothing (lstattachment) AND lstattachment.Any()

help would be appreciated , thanks in advance,

To check if variable is empty or not use this String.isnullOrempty (your_varible) this will return true if variable is empty else false will return

@kalyanDev : Its a Enumerable object List , we cannot apply isNullorEmpty on an Enumerable object here thanks for your time,

If it is list you can do one thing try this list.count this will count if is !0 then items are exist in list else no items in list means list is empty
like this

If (list.Count==0){
      //logic
    } else {
      //logic
    }
1 Like

@kalyanDev if the list is an valid object i can use above code , but here list itself null so i cannot chain the count function

@velanchandru you are using one list variable right are you initialized that variable like this
list = new list(of strings) if you initialized the list then count function will work try like this once

@kalyanDev its worked thanks for your time :slight_smile:

Welcome :grinning: mark as a solution so that it will helpful for others also easily.

Hi @velanchandru,

Please try the following -

(lstattachment is Nothing)

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.