Free Support Forum - aspose.com

Execute followed by ExecuteWithRegions results in InvalidCastException

When calling MailMerge.Execute followed by MailMerge.ExecuteWithRegions I get an exception.

System.InvalidCastException: Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Fields.FieldStart'.

The solution until a fix is supplied is to save the result from first Execute to a stream. Create a second Document from the stream and call ExecuteWithRegions on the second document.

/Uffe

Hello

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

Thanks for your request. Could you please attach your template document and simple code here for testing? I will check the issue on my side and provide you more information.

Best regards,

Sample code to reproduce problem.

static void Main(string[] args)
{
var doc = new Document(@"test.template.docx");
doc.MailMerge.Execute(new string[] { "Anvandare_Namn" }, new object[] { "username" });

var ds = new DataSet();
ds.ReadXml(@"datatable.xml");
var dataTable = ds.Tables[0];

doc.MailMerge.RemoveEmptyParagraphs = true;
doc.MailMerge.ExecuteWithRegions(dataTable);

//Exception. Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Fields.FieldStart'.
}

Update: Aspose.Words 9.3 is used.

/Uffe

Hello

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

Thank you for additional information. I managed to reproduce the problem on my side. You will be notified as soon as it is resolved.

It seems there is something wrong with Styles of merge fields. As a workaround you can try clearing styles of merge fields inside region or you can modify the TOC field. As a temporary workaround, you can try using the following code of TOC field and the problem disappears: TOC \o "1-1" \h \z \t

Best regards,

This looks like the exact problem i’m having. Hope you boys find a solution soon…

Hello Abe,

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

Thanks for your request. I just answered to you here:

Best regards,

A fix for the issue(s) you've reported (filed as 19051) will be released in the next release at the end of this month. You will be notified.


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

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


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