ListMessages throwing Index was out of range. "Must be non-negative and less than the size of the collection." error

I am using v6.4.0.0 of aspose email. I have an mvc based unit test that gets called to test our email system. a code sample below shows how we are sitting in a loop after an email has been sent and waiting for the email to arrive. I believe i can run this just fine if i kick off the test once, but if i kick off the two tests at once, i seem to always get the exception thrown at the bottom of this email. Is there some kind of issue in a multiuser scenerio with aspose.email or any ideas on why this would be happening?



var messages = client.ListMessages(query, 1);
while (!messages.Any() && (endTime > DateTime.Now))
{
Thread.Sleep(sleepTime);
this.LogTestMessage(string.Format(“Searching for email <{0}>”, emailGuid));
messages = client.ListMessages(query, 1);
}
if (!messages.Any())
{
var message = string.Format(“Failed to receive test email <{0}> within {1} seconds”, emailGuid, secondsToWait);
Assert.Fail(message);
}
else
{
var item = messages.FirstOrDefault();
client.ChangeMessageFlags(item.UniqueId, ImapMessageFlags.IsRead);
}



Exception:
System.ArgumentOutOfRangeException was unhandled by user code
HResult=-2146233086
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
ParamName=index
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Aspose.Email.Imap.ImapClient.#=qWmoHBgTI7qMaf2G7SYVDXw==(#=qgxroqfT1DK7hLbwpq99gTBvzekEcoW2BPv$LDp3V5A9eeSdL71e9$34fPrmJcDlS #=q96sQn_AFF6Cek6hDQPMWNQ==, String #=qNy9asJiys_bxITrhdzbOpw==, MailQuery #=qvMe2bRu4ClD$2pUPX3Gs_g==, Int32 #=qAzDWP1T43GIDG0wCKF$Bgw4ilPQo5TAzigvysyBbpu4=)
at Aspose.Email.Imap.ImapClient.ListMessages(MailQuery query, Int32 maxNumberOfMessages)
at Zywave.Status.Mail.Web.Controllers.StatusController.TestEmail(ServiceClientFactory serviceClientFactory) in C:\Projects\Status\Sites\Zywave.Status.Mail.Web\Trunk\Zywave.Status.Mail.Web\Controllers\StatusController.cs:line 85
at Zywave.Status.Mail.Web.Controllers.StatusController.DefaultTest() in C:\Projects\Status\Sites\Zywave.Status.Mail.Web\Trunk\Zywave.Status.Mail.Web\Controllers\StatusController.cs:line 33
InnerException:

Hi Kirk,

Thank you for contacting Aspose Support team.

We have looked into your test code from our perspective and also tried the same at our end. It doesn’t raise any issue and the email count is listed properly. Can you please elaborate what you mean by “
but if i kick off the two tests at once, i seem to always get the exception thrown at the bottom of this email”. If possible, please share your sample MVC project with us that can be used to reproduce this issue. We’ll look into it and share our feedback with you.

So this is basically an MVC site with a page that allows you to run the test manually with button. if i open up two browsers pointing to site url and then click on browser 1 page button and then click on browser 2 page button, so now two different tests are running at the same time, I get the error listed above.


Unfortunately it would be hard to give you our exact code because the email server we are using to test email receipt is internal only. if you have a mail server you can use to test receipt of an email, it would be rather easy to make your own version of this test from an mvc or asp.net web page. doesnt really matter the technology, its more about being able to kick off the test more than once, as in two browsers connected to your localhost url.

test scenerio
- send email to your test email server mailbox.
- wait in a loop and use IMAP to keep checking box for the email based on subject

I have attached our mvc controller test so you can see the basic principal. you can just replace the sending of the email with that IQuerUser service call with just normal .net smtp client send.

Kirk

Hi Kirk,

We used the same logic at our end previously while testing the issue. Please spare us a little time to investigate the issue further. We’ll share our feedback with you here soon.

Hi Kirk,

We have further investigated this issue at our end with a WinForm applicaiton where two buttons run the same test in parallel threads. No such issue was faced as you have mentioned. Please check the attached sample project that we have used for testing this issue further. The email is sent directly from outlook to our test account that we check in a loop for message arrival. You may please check it at your end and share your feedback with us if it raises exception. Also, you may modify the application (if required) and share with us back for reproducing the issue at our end.

is it ok if i send test emails to the account in that winformapplication? what is the full email address? without the delay that can occur with sending email, i dont know if this will fail.

Hi Kirk,


You can use this account for testing. Full email address is asposeemail.test4@aspose.com. Please feel free to share the feedback after testing.