Free Support Forum -

Document.Save crashes while executed within MailMergeEventHandler

When i try to save a document during a mailmerge from within a MailMergeEventHandler, the Document.Save() crashes.

I'm getting an System.InvalidCastException with the message: "Unable to cast object of type '㜓.㜥' to type 'Aspose.Words.Section'."

I'm only getting this exception when i use the:

doc.MailMerge.Execute(new string[] { "MyField" }, new object[] { "bla" });

The problem does not occur when I'm merging data in a DataTable neither does it occur when using an custom implemented IMailMergeDataSource.

I've noticed that the Document object within the MailMergeEventHandler has an extra section compared with the original document that was used to perform the mailmerge.

Hopefully you can help.


<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I managed to reproduce the problem on my side and created new issue #9080 in our defect database. I will notify you as soon as it is fixed.

Best regards.


Yes, you are correct. While being merged, a document is in an "unstable" state meaning new regions are being created and inserted. Some special node types used as region placeholders are temporarily inserted, and that's what is causing problems saving a document in this state.

But could you please explain why would you need to save a document in a mail merge event handler? I am sure that there is a more suitable way to achieve that.


The issues you have found earlier (filed as WORDSNET-2395) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.