I’m seeing a lot of exceptions similar to this issue in Aspose Words: Execute Multiple Mail Merge Jobs on Word DOC Document in Multi-Threaded Environment using C# .NET Core 3.1 - #8 by awais.hafeez however my case happens to be in Aspose PDF. They all come from Aspose PDF (20.10), I’m not sure if I’ve seen them before at previous Aspose versions. Error message:
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.
Stacktrace:
System.InvalidOperationException handled at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw:
at System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Collections.Generic.Dictionary`2.FindEntry (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Collections.Generic.Dictionary`2.TryGetValue (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at #=z0aJDmtQnP84snmHpgfuK6$DjlaXZRcG1988lRy17OaOS.#=znApDZJx9x$yI (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zLS0bXYESTwt6s9O9ge8mODhIHcBqPm8DK6a4oJzbJTUC.#=znApDZJx9x$yI (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=z_uXQUUTOD1x0nWp6D5Ny5LEcgnC37hfuk8cHGMuX19$GM6bj4vQNFj1LL6lC.#=zBSTPq1n1lngm (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=z_uXQUUTOD1x0nWp6D5Ny5LEcgnC37hfuk8cHGMuX19$GM6bj4vQNFj1LL6lC..ctor (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=z8YwyAFpXu4Vn5VQFGpzWPjJpGglVYuDGSWGaixo=.#=z5omiAE4sn21L (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zdcZDrO$CfWmPF8bE9CCtiaeTKraBRfAGOrweiyBrLoUG.#=zSwIrxxKT9uY6 (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zdcZDrO$CfWmPF8bE9CCtiaeTKraBRfAGOrweiyBrLoUG.#=z$Wj18moou5Zf (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=z8JzRwMDnRYyPoUkGXOTktNTf9Or5NT3JP5iULXY=.#=z$Wj18moou5Zf (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zdcZDrO$CfWmPF8bE9CCtiaeTKraBRfAGOrweiyBrLoUG.#=z$Wj18moou5Zf (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=z1n61tGKXQVHtqVBtOwBlS9qoA3RmKZO6u5bOXfEmXdYmB57A5cQFpGdl5Mzn$qXVWCb9iFA=.#=zl9b8KPg= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zUr3fyKG1IneV0AIo$ZJrHNxAgCWrMOraZO9msTDB6W4L1s$Be5ATPPU=.#=zKLJ78x8= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zUr3fyKG1IneV0AIo$ZJrHNxAgCWrMOraZO9msTDB6W4L1s$Be5ATPPU=.#=zoy51kyn5v9so (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zigVcVy0kF4TRalKjQfSZwcYEHcgRyhXISOYJy89zQBEgDdBz12CmBt8=.#=zkQP5G2JfByd1 (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zigVcVy0kF4TRalKjQfSZwcYEHcgRyhXISOYJy89zQBEgDdBz12CmBt8=.#=z5vO83PVKfXp1 (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=zigVcVy0kF4TRalKjQfSZwcYEHcgRyhXISOYJy89zQBEgDdBz12CmBt8=.#=z5vO83PVKfXp1 (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextState.set_Font (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextState.#=z0hdiJwi8kekC (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextState.#=zhbn1PHk= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextSegment.#=zhbn1PHk= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextBuilder.#=zIPkcA5E= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Text.TextBuilder.#=zo7_2BsVc87cY (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=ztfmBK0IQTD8RH0KlEQr_DdejyCjPQVXjh$3yOafcgxPT9LWvqZUqels=.#=z2pyN7$M= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at #=ztfmBK0IQTD8RH0KlEQr_DdejyCjPQVXjh$3yOafcgxPT9LWvqZUqels=.#=zQIB0o7k= (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at Aspose.Pdf.Document.Convert (Aspose.PDF, Version=20.10.0.0, Culture=neutral, PublicKeyToken=f0262d67fe233d63)
at MyOCRCode
A bit simplified my code boils down to this:
using var input = new Document(pdfStream);
doc.Convert(GetHocr);
where GetHocr
is a function definition taking an image to extract the text.