Please examine error message carefully. Remember to use Imap.Select or Imap.SelectInbox before you try to get any messages.
Most likely the UID you try to use doesn't exist in the selected folder anymore.
Imap.GetMessageByUID is one of the core methods of Mail.dll .NET IMAP client, there is almost no chance it works incorrectly.