Exception"Index out of range" on extracting message from PST(C#)

When extracting messages from the PST

With the code below.

I get the following exception:

Saving AAAAAJMxOHZCV4pMuQ4tEgo2fkeEYyAA at 5/29/2019 5:12:39 PM

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=zrDEU88dPSeXy(String #=zJmbxurc=, String #=ztxtvnsmJsYNI)
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=z8Hv5O7E=(String #=znLJBU9g=, StringBuilder #=z4M10kjc=)
at #=zI5JwC3ZCgW4HTj1bZpUcUucQt3p1cvC0LtaJ9wZGQw8o.#=z9YFcLOU=(String #=z_JfOGA_zhkbY)
at #=zWAWrInA$rr783lhXkXnK7OEeLwa1AOiWkA==.#=zSyV72edmzIdh(String #=z_JfOGA_zhkbY)
at #=zSqj10qCjZCEFV6a3UtavEhJU_ZhJl2RlVnKNeLc=.get_Data()
at #=z72k7a$mdzj3v_55eqYKXq2yV4hRs7EwypYnyW_s=.#=z5O6RE5nknLRF(UInt32 #=zA936i6zVftzP, Stream #=zVhu4sBU=)
at Aspose.Email.Storage.Pst.PersonalStorage.SaveMessageToStream(String entryId, Stream stream)
at PstTester.repro.ExtractPst(String pstfilename) in C:\Users\Administrator\Documents\GitHub\disco-batch\tools\PstTester\PstTester\repro.cs:line 27

        filePath = "JAN-5174.pst";

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Aspose.Email.Storage.Pst;

namespace PstTester
class repro
public static void ExtractPst(string pstfilename)
string path = pstfilename;

        // Save message to MemoryStream
        using (PersonalStorage personalStorage = PersonalStorage.FromFile(path))
            List<string> allMessageIds = GetAllMessageId(personalStorage.RootFolder);

            foreach (string entryIdString in allMessageIds)
                using (MemoryStream memorystream = new MemoryStream())
                    Console.WriteLine("Saving {0} at {1}", entryIdString, DateTime.Now);
                    personalStorage.SaveMessageToStream(entryIdString, memorystream);
                    Console.WriteLine("Saved {0} at {1}", entryIdString, DateTime.Now);


    static List<string> GetAllMessageId(FolderInfo folder)
        List<string> messageIdList = new List<string>();

        var messageIds = folder.EnumerateMessagesEntryId();


        var subFolders = folder.EnumerateFolders();
        foreach (var subFolder in subFolders)
            var someMessageIds = GetAllMessageId(subFolder);

        return messageIdList;



I have investigated this issue on my end have been able to observe the issue. An issue with ID EMAILNET-39487 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

The issues you have found earlier (filed as EMAILNET-39487) have been fixed in this update.