Execute Multiple Mail Merge Jobs on Word DOC Document in Multi-Threaded Environment using C# .NET Core 3.1

Hi,

When running running 1 document mail merge at a time I have no errors. When running multiple jobs at at time. Completely independent of each other I run into the below error. This is causing issues as we need to generate 20,000 mail merged files.
My guess is it is linked to a static Dictionary under the covers.

System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.

at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at .(Char )
at .(Int32 )
at .(Int32 )
at . (Int32 )
at . ( , Boolean )
at .( , , , Boolean )
at .(String , , Boolean )
at ​ . (Boolean )
at ​​ . (Int32 , Boolean , Boolean )
at ​​ . (Int32 , Boolean )
at ​​ .​​ (Int32 )
at Aspose.Words.Fields.FieldMergeField. (​​ , MailMerge )
at Aspose.Words.Fields.FieldMergeField. (​​ )
at Aspose.Words.Fields.FieldMergeField.86q6acmbfp2kjwdcs2q6rs3uwmqt2zc9 ()
at Aspose.Words.Fields.FieldMergeField.86q6acmbfp2kjwdcs2q6rs3uwmqt2zc9 (FieldStart , FieldSeparator , FieldEnd )
at .(FieldStart , FieldSeparator , FieldEnd )
at . ()
at . ()
at .VisitFieldEnd(FieldEnd )
at Aspose.Words.Fields.FieldEnd.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Tables.Cell.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Tables.Row.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Tables.Table.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Body.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Section.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Document.Accept(DocumentVisitor visitor)
at . (Node )
at . (Node , Boolean , FieldType[] )
at . (Node , Boolean )
at . (Node )
at . (Node )
at Aspose.Words.MailMerging.MailMerge. ( )
at Aspose.Words.MailMerging.MailMerge.ExecuteWithRegions(IMailMergeDataSource dataSource)

@andymac4182,

Have you also tried the latest (20.5) version of Aspose.Words for .NET on your end?

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document(s) you are getting this problem with
  • Please also create a standalone simple Console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you more information. Thanks for your cooperation.

Hey,

Sorry I forgot to include I am using .net core 3.1 with package version 20.5.

I will try to make up an app to replicate the issue.

@andymac4182,

Sure, we will wait for your further input on this topic. Please provide a sample console application and related resources (documents etc) so that we will be able to reproduce/replicate the same problem on our end.

Here is an example :slight_smile: It replicates on my machine but you might need to adjust the number of threads depending on how powerful the machine is.

@andymac4182,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-20533. We will further look into the details of this problem and will keep you updated on the status of the linked issue. Sorry for the inconvenience.

Thanks @awais.hafeez We are looking to go to production this week. Is there an idea how long till you have time to investigate?

@andymac4182,

I am afraid, your issue is currently pending for analysis and is in the queue. There are no estimates available at the moment. Once the analysis of this issue is completed and the root cause is determined, we may then be able to calculate and share the ETA of this issue with you. We apologize for any inconvenience.

@andymac4182,

Regarding WORDSNET-20533, it is to inform you that we are no longer able to reproduce this issue when using the latest (20.6) version of Aspose.Words for .NET on our end. So, you please also try the 20.6 version of Aspose.Words and let us know how it goes on your end? Hope, this helps.

Thanks for this. I will give it a go today :slight_smile:

The issues you have found earlier (filed as WORDSNET-20533) have been fixed in this Aspose.Words for .NET 20.7 update and this Aspose.Words for Java 20.7 update.