Error Getting Messages.Count() Object reference not set to an instance of an object.

Topics: Help requests
Feb 11, 2014 at 10:57 PM
Hi there guys im having problemas getting the count of the messages of the infox heres is my code:
  ImapClient client = new ImapClient("imap.gmail.com", 993, true, true);
        bool connect = client.Connect();
        client.Login("12345@gmail.com", "passwordhere");
        client.Behavior.AutoPopulateFolderMessages = true;
  

        Button1.Text = client.Folders.Inbox.Messages.Count().ToString();
I get the error: Object reference not set to an instance of an object.
In that line but the log in and all that is OK


I hope you guys can help me

Thanks
Coordinator
Feb 12, 2014 at 10:54 AM
Hi rodolfolopes,

I think the exception is thrown because the folders are not getting intialized. From your code above, I can say that you should check if the client has connected and authenticated. Simply check if both, the result of _ImapClient.Connect _and ImapClient.Login are true.

Greets,

Pavel