System.IndexOutOfRangeException when save document

hi,
could you please tell me what is reason thrown below exception? our production use aspose.word 9.3.0.0 and always get below exception latest, sorry, I can’t attached any .doc for security reason, but I can tell you the .doc is very simply and it was work fine. I had tried to use an empty .doc and also got the exception in our environment.
just provided a issue sample.doc file for investigating.
our code like:

Aspose.Words.Document document;...
document.MailMerge.Execute...

document.UpdatePageLayout();
document.Save(..., SaveFormat.Doc); // thrown the exception
HandlingInstanceID: cdc83931-ca65-4b6f-8f6d-25ac9fd5272b An exception of type 'System.IndexOutOfRangeException' occurred and was caught. 
---------------------------------------------------
---------------------------- 21/04/2011 17:25:34 
Type : System.IndexOutOfRangeException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Index was outside the bounds of the array. Source : Aspose.Words Help link : Data : System.Collections.ListDictionaryInternal TargetSite : Int32 x792b6f092cbf4bb1(Int32[], Int32, Int32, Int32) Stack Trace :
at x6c95d9cf46ff5f25.xcd4bd3abd72ff2da.x792b6f092cbf4bb1(Int32[] x9d5750eb2d6373bc, Int32 xc0c4c459c6ccbd00, Int32 x961016a387451f05, Int32 xbcea506a33cf9111)
at x6c95d9cf46ff5f25.x09ce2c02826e31a6.set_xe6d4b1b411ed94b5(Int32 xba08ce632055a1d9, Object xbcea506a33cf9111)
at x28925c9b27b37a46.x4c1e058c67948d6a.x43c6155e35f47d2b(Int32 xba08ce632055a1d9)
at xa604c4d210ae0581.xa55b88ee4e81381b.WriteCore()
at xa604c4d210ae0581.x485adbf5506556e8.x6210059f049f0d48(x7f77ea92be0d9042 x94aec03cf2ae750b)
at x9e260ffa1ac41ffa.x163859bfa28558c4.xfc53bd8a6982db4c()
at x9e260ffa1ac41ffa.x163859bfa28558c4.VisitRowEnd(Row row)
at Aspose.Words.Tables.Row.x3bbb475596fa1de1(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Row.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Table.Accept(DocumentVisitor visitor)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x6075c9125351e131(CompositeNode x03e7e66b1eecc96f)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x51ee56decc29a9da(Section xb32f8dd719a105db)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x160a0bf4de8f6bd0()
at x9e260ffa1ac41ffa.x163859bfa28558c4.x8cac5adfe79bc025(x8556eed81191af11 x5ac1382edb7bf2c2)
at Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c)
at Aspose.Words.Document.Save(String fileName, SaveOptions saveOptions)
at Aspose.Words.Document.Save(String fileName, SaveFormat saveFormat)

Hello,
Thank you for your inquiry.
If you get this even with a blank document, then could you create a simple application that would allow us to reproduce the problem. Just try to please use the latest version of our product 9.8.0.0. You can download it here. Maybe it will solve the problem.

hi
Thanks for your suggestion, but the case is we always get the exception on our environment now. I want to know what is reason can cause it for it was work fine before. I have attached an issue sample.doc let your team to check.
thanks

Thank you for additional information.
You forgot to attach the document.
Have you tried to update aspose.words to version 9.8.0.0?

Hi
I don’t think it is good idea before didn’t know what is issue cause always got the exception and don’t think upgrade aspose will resolved the issue if the root cause is some environment changes impact aspose didn’t work. I hard to get usfull information from exception log stack trace of aspose thrown, I suspect it is cause by some environment changes, so need your team help to address which kind of issues it is. e.g. rendering, lack fonts, or some other dependencies.
issue sample.doc had been attached.
thanks

Thank you for additional information.
Unfortunately I was unable to reproduce your problem on my side.
Could you create a simple application that would surely could reproduce your problem. I used the following code and your template.

var license = new License();
license.SetLicense("Aspose.Words.lic");
DataTable table = new DataTable("Test");
table.Columns.Add("Office name");
table.Columns.Add("Office address 1");
table.Columns.Add("Office address 2");
table.Columns.Add("Office TPT email");
table.Columns.Add("MS website");
table.Columns.Add("Office header phone number combined");
table.Columns.Add("Office fax");
table.Columns.Add("Current date");
table.Rows.Add(new object[]
{ "name"
, "address1"
, "address2"
, "email@mail.com"
, "http:\\\\website.com"
, "333-444-555"
, "000-111-222"
, "01.01.2011"});
Document doc = new Document("X:\\issue+sample.doc");
doc.MailMerge.Execute(table);
doc.UpdatePageLayout();
doc.Save(string.Format("X:\\out.pdf"), SaveFormat.Pdf);

In the attach my out file.

hi
Thanks for your helps, yes, I also can’t to reproduce it on my PC like your codes, ours program is standard Window service which is host for keeping generate document by multiple thread, I found after hours ours windows service keeping running, the exception will happenning, once restart service, the exception gone, could you help advise?
multiple thread sample:

public class AsyncHelper : IDisposable
{
    private static object lockObj = new object();

    private const int MIN_THREADS = 1; //TODO: set 1 to debugging purpose only. Should be 2.
    private const int MAX_THREADS = 20;
    private const int waitAllTimeout = 120;
    class State
    {
        public ManualResetEvent manualEvent { get; set; }
        public Func Operation { get; set; }
    }
    private bool _isDisposed;
    Action _action;
    ManualResetEvent[] manualEvents;
    public AsyncHelper() : this(10)
    { }

    ///
    /// Specified a value of maximum threads, the value must between 2 and 20.
    ///
    /// Specified a value of maximum threads, the value must between 2 and 20.
    public AsyncHelper(int maxThreads) : this(maxThreads, null)
    { }
    public AsyncHelper(Action action) : this(10, action)
    { }
    public AsyncHelper(int maxThreads, Action action)
    {
        if (maxThreads < MIN_THREADS || maxThreads > MAX_THREADS)
            throw new ArgumentException(string.Format("The maximum number of threads must between {0} and {1}.", MIN_THREADS, MAX_THREADS));
        _action = action;
        manualEvents = new ManualResetEvent[maxThreads];
        for (int i = 0; i < manualEvents.Length; i++)
        {
            manualEvents[i] = new ManualResetEvent(true);
        }
    }
    public void Run(Func func, T param)
    {
        int index = WaitHandle.WaitAny(manualEvents);
        ManualResetEvent manualEvent = manualEvents[index];
        manualEvent.Reset();
        func.BeginInvoke(param, Done, new State
        {
            manualEvent = manualEvent,
            Operation = func
        });
    }
    void Done(IAsyncResult ar)
    {
        State state = ar.AsyncState as State;
        if (state == null) return;
        try
        {
            var result = state.Operation.EndInvoke(ar);
            if (result != null && _action != null)
            {
                _action(result);
            }
        }
        catch (Exception ex)
        {
            // exception handling
        }
        finally
        {
            if (state.manualEvent != null)
                state.manualEvent.Set();
        }
    }
    public bool WaitAll()
    {
        return WaitHandle.WaitAll(manualEvents);
    }
    public bool WaitAll(int millisecondsTimeout)
    {
        return WaitHandle.WaitAll(manualEvents, millisecondsTimeout, false);
    }
    public int WaitAny()
    {
        return WaitHandle.WaitAny(manualEvents);
    }
    #region IDisposable Members
    public void Dispose()
    {
        this.WaitAll(waitAllTimeout * 1000);
        Dispose(true);
        GC.SuppressFinalize(this);
    }
    protected void Dispose(bool disposing)
    {
        if (!_isDisposed)
        {
            if (disposing)
            {
                foreach (var item in manualEvents)
                {
                    if (item != null)
                        item.Close();
                }
            }
        }
        _isDisposed = true;
    }

    ~AsyncHelper()
    {
        Dispose(false);
    }
#endregion

BTW:
also got below exception from aspose first, after thrown many times later, it will always System.IndexOutOfRangeException

HandlingInstanceID: 7172829f-0e2a-4bad-9eb4-99213c903c54 An exception of type 'System.ArgumentOutOfRangeException' occurred and was caught. ---------------------------------------------------------------------------------- 28/04/2011 15:19:21 Type : System.ArgumentOutOfRangeException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Specified argument was out of the range of valid values. Parameter name: index Source : Aspose.Words Help link : ActualValue : ParamName : index Data : System.Collections.ListDictionaryInternal TargetSite : Void x7121e9e177952651(Int32) Stack Trace :
at x6c95d9cf46ff5f25.x09ce2c02826e31a6.x7121e9e177952651(Int32 xc0c4c459c6ccbd00)
at xa604c4d210ae0581.xa55b88ee4e81381b.WriteCore()
at xa604c4d210ae0581.x485adbf5506556e8.x6210059f049f0d48(x7f77ea92be0d9042 x94aec03cf2ae750b)
at x9e260ffa1ac41ffa.x163859bfa28558c4.xfc53bd8a6982db4c()
at x9e260ffa1ac41ffa.x163859bfa28558c4.VisitRowEnd(Row row)
at Aspose.Words.Tables.Row.x3bbb475596fa1de1(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Row.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.x464d2134480a7bf2(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.CompositeNode.xf7ae36cd24e0b11c(DocumentVisitor x672ff13faf031f3d)
at Aspose.Words.Tables.Table.Accept(DocumentVisitor visitor)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x6075c9125351e131(CompositeNode x03e7e66b1eecc96f)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x51ee56decc29a9da(Section xb32f8dd719a105db)
at x9e260ffa1ac41ffa.x163859bfa28558c4.x160a0bf4de8f6bd0()
at x9e260ffa1ac41ffa.x163859bfa28558c4.x8cac5adfe79bc025(x8556eed81191af11 x5ac1382edb7bf2c2)
at Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c)
at Aspose.Words.Document.Save(String fileName, SaveOptions saveOptions)
at Aspose.Words.Document.Save(String fileName, SaveFormat saveFormat)

Hi
Thank you for additional information. But could you also create a simple application that will allow us to reproduce the problem? We will check the issue again and provide you more information.
Also, as I can see you call UpdatePageLayout before saving the document as DOC. You can try removing this call of UpdatePageLayout this might resolve the problem and makes the process of generating document faster. There is no sense to call UpdatePageLayout before saving document as DOC because DOC format is flow format.
Best regards,

Hi
I manage to reproduce the exception on my other PC by sample program, the case as I said, above codes is what only I can provide, we call UpdatePageLayout method is because there are some issues showing when .doc contains some table of contents, all content page number were show like ??? … ???. (save as .pdf directly after mail merged)
thanks

Hi
Thank you for additional information. If after updating fields in the document you see ??? instead of page numbers in TOC, then I suppose you are using old version of Aspose.Words. The latest version of Aspose.Words does not require calling UpdatePageLayout to update page numbers in TOC. In the latest version you need call only UpdateFields.
So, please try using the latest version of Aspose.Words and let me know how it goes on your side. You can download the latest version from here:
https://releases.aspose.com/words/net
Best regards,