Free Support Forum - aspose.com

Index was outside the bounds of the array - C#

Hello,
I am trying to loop through the emails in a NSF file. using EnumerateMessages() and it is throwing the ‘Index was outside of the bounds array’ exception.

Code:
using (NotesStorageFacility nsf = new NotesStorageFacility(fi.FullName))
{
try
{
foreach (MailMessage eml in nsf.EnumerateMessages())
{
emlCount++;
}

                }
                catch (Exception ex)
                {
                    Console.Writeline(fi.FullName + ": " + ex.Message);
                }
                finally
                {
                    nsf.Dispose();
                }

            }

Using Aspose.Email v21.1.1

Stack trace:
at #=z7KViMIi8j3uywo6UQ5$U1wI_0PwfNeBVYQ==…ctor(Byte[] #=zf9sWXEI=)
at #=zLzal_mBZwSFChgpA1FmlsaRHCu2kuJhXKA==.#=z$cyJo2kNP3LjxDJeYQ==(#=z8n_e3IU_UJvLVENGTgp59I6lJlgNCkx39A== #=zWXBnFd3ZCM3z)
at #=zLzal_mBZwSFChgpA1FmlsaRHCu2kuJhXKA==.#=zL1$$c54=(Int32 #=zCwUj4D0=)
at #=zLzal_mBZwSFChgpA1FmlsaRHCu2kuJhXKA==.#=z_LbFvZWmStJN.MoveNext()

Thanks in advance.
Wynne

@wynneIQ

In order to proceed further with issue investigation and resolution on our end, I suggest you to please share the working sample code and NSF file reproducing issue on your end.

Here is the code:
DirectoryInfo d = new DirectoryInfo(folder);
FileInfo[] Files = d.GetFiles("*.nsf");

        foreach (FileInfo fi in Files)
        {
            emlCount = 0;
            using (NotesStorageFacility nsf = new NotesStorageFacility(fi.FullName))
            {              
              
                try
                {                    
                  
                    foreach (MailMessage eml in nsf.EnumerateMessages())
                    {
                        emlCount++;
                    }
                    
                    Console.WriteLine(" Eml count: " +  emlCount);
                }
                catch (Exception ex)
                {
                    Console.WriteLine( ex.Message);
                }
                finally
                {
                    nsf.Dispose();
                }

            }
        }

But unfortunately I cannot supply the nsf file since it contains actual client data. But here is a screen shot of another tool that was able to parse the file:

NSF-file.PNG (31.7 KB)

@wynneIQ

Actually, the issue is centric towards the NSF file rather code itself. Therefore, in order to proceed further with issue investigation, I request you to please share the source file reproducing the issue.