Exception on DocumentModel.Clone(true)


We have an exception occuring randomly on the method "DocumentModel.Clone(bool descendants)’
In our code, we previously load an docx as a template.
It worked great for weeks, and now this error randomly occurs.

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List1.Enumerator.MoveNextRare() at  .  (DocumentModel , DocumentModel ) at  . [T](T , Action2 )
at  .(Element , Boolean , ImportMapping )
at GemBox.Document.DocumentModel.Clone(Boolean cloneDescendants)
at xxxxx.BAL.yyyyyyyy.GeneratePdf.GenerateSpecificDocument(SpecificDocument specificDocument) in .…\pipelines\Compilation_MicroServices.….…\GeneratePdf.cs:line 767
at System.Threading.Tasks.Parallel.<>c__DisplayClass33_02.<ForEachWorker>b__0(Int32 i) at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
— End of stack trace from previous location where exception was thrown —
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) at System.Threading.Tasks.TaskReplicator.Replica1.ExecuteAction(Boolean& yieldedBeforeCompletion)
at System.Threading.Tasks.TaskReplicator.Replica.Execute()

Using Gembox.Document Version=“33.0.1086”
Thanks for your help

Hi David,

I was unable to reproduce this issue.

Just in case, please try again with the current latest version:

If the problem remains, please send us your document so that we can try reproducing your issue.


Thanks for this check.
As I said, this is random, evenif this is always the same “docx” file as template.
This occurs in Production environment, and we did not reproduced it in our test or local dev environments.
We thought at first of a parallelism issue, so we tried with hundreds of calls in a dev envroment, and even with that, no reproduction.
Ok, we’re going to try with a new version