Click here to Skip to main content
13,295,828 members (56,048 online)
Rate this:
Please Sign up or sign in to vote.
Dear Coders,

I've just started using your ImapX library to retrieve and read mails from gmail.
Now, everything is working fine and it's a great library.

However, when i'm trying to mark a mail read using the Message.Process() option, it returns the IndexOutOfRangeException.

private void Start()
            int amountRead = 0;
            foreach(string origin Properties.Settings.Default.MailOrigins)
                IMailOriginAdapter adapter = MailOriginFactory.CreateMailOriginContainer(origin);
                foreach (ImapX.Message message in adapter.Messages())
                    if (SendWebRequest(url))
                        Dispatcher.BeginInvoke(new MethodInvoker(delegate
                            this.btnStart.Content = "Read [" + amountRead + "/" + GmailUser.Instance.Messages.Count + "]";
                System.Windows.MessageBox.Show(adapter.GmailFromEmail() + " reading completed.");

Or in a more simple example:

private void worker_DoWork(object sender, DoWorkEventArgs e)
            foreach (Message message in adapter.Messages())

Hopefully someone's capable of helping me with this problem which i've had now for over then a month..

Thanks in advance.

Yours Sincerely,
Posted 15-Feb-13 6:54am
Updated 16-Feb-13 6:22am
Sergey Alexandrovich Kryukov 15-Feb-13 14:11pm
It does not "return" exception. Exceptions are not returned, they work "over" the usual stack call-return mechanism.
In what line?
Did you use the debugger to see how the range and actual values match? Such problems usually easy and are best resolved with the debugger.
larssy1 16-Feb-13 11:27am
Hi Sergey,

The line where the error occurs is on the message.Process() line.
When trying to press F11 (step into), it returns a call stack error on line 144 in Message.cs of the ImapX Library.

Everything about the message object in my code, seems to be fine.

Any Ideas?

Sergey Alexandrovich Kryukov 16-Feb-13 19:13pm
I don't see your line numbers. You can simply comment the lines in question and reference by those comments. What's "call stack error"? How about exact exception full type name and message? see also internal exception.
larssy1 19-Feb-13 18:02pm
Please see the following screenshot for the Exception object.

This error message is while executing the following code:

try { message.Process(); }
catch (Exception ex)
String s = ex.Message;
Sergey Alexandrovich Kryukov 19-Feb-13 18:04pm
"Error message"? Exception? What line?
larssy1 19-Feb-13 18:08pm
Haven't those items been said before??

1. "Index was outside the bounds of the array."
2. IndexOutOfRangeException
3. The Message.Process() line, there is only one message.Process() coming back in every bit of code i'm posting..
Sergey Alexandrovich Kryukov 19-Feb-13 18:18pm
I see, thank you. Can you "get into" message.Process while debugging? The problem is that this code may be without source code... You can try to set breakpoints on other points of your code before this call. I don't know exactly... I'm sure I would debug it, if I had the whole code... I see nothing suspicious in the code you show, but the problem could be elsewhere.
larssy1 20-Feb-13 2:11am
I have tried indeed.. And yes, the source code is in the library, and because of that I'm unable of debugging.

The problem is that my code works perfectly without using the "Message.Process()" line, simply when i'm trying to implement is, it's throwing me this bug..

This indicates for me that the problem should be in the library,, but many other users don't seem to have problems with it..
Sergey Alexandrovich Kryukov 20-Feb-13 11:36am
I understand. That's exactly the case I mentioned: you get into the library code.

There is a chance. Process is on the library, but it will call your methods, so the thread will eventually come back to the code your have the source code for. It's a matter of catching it using some educated guess. After all, for initial catch, put break points at the beginning of very many of your methods, but education guess helps.

Usually, it's easy enough.

There are harder alternatives: 1) Microsoft provided .NET source code, mostly for debugging purposes, it can be installed the way VS debugger gets into it; 2) You can use open-source ILSpy, where you can debug using compiled code, it decompiles it. You can switch from CIL to C# and back. The link is found under Wikipedia article "Reflector"...


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100