You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was using the InsertParagraphAfterSelf method of Paragraph to insert paragraphs from one document to another without issues until release 2.4 (including 2.4.1), but the code is now throwing an error if I update DocX to 2.5.0 or the latest 3.0.0
Collection was modified; enumeration operation may not execute.
In Paragraph, using the InsertParagraphAfterSelf or InsertParagraphBeforeSelf methods no longer breaks the Paragraphs collection.
Is there a chance there is a regression?
My code (edited) is next; InsertParagraphAfterSelf(paragraph) is successful the first time, but the next iteration always throws the above-referenced error.
foreach (var par in subdocument.Paragraphs)
{
if (par.Hyperlinks.Count > 0)
{
Paragraph paragraph = template.InsertParagraph();
foreach (var magicWord in par.MagicText)
if (string.Equals(magicWord.formatting?.StyleId?.ToLower(), "hyperlink"))
{
paragraph.InsertText(string.Concat("[[", magicWord.text, "]]"), false, magicWord.formatting);
}
else
paragraph.InsertText(magicWord.text, false, magicWord.formatting);
bookmarkParagraph = bookmarkParagraph.InsertParagraphAfterSelf(paragraph);
}
else
{
bookmarkParagraph = bookmarkParagraph.InsertParagraphAfterSelf(par);
}
}
Thanks!
The text was updated successfully, but these errors were encountered:
Is this still an issue in the latest v3.0.0 version from NuGet ? I've updated your sample to be able to run it and I saw no exception. I attached my test.docx file.
Here's the sample I used :
var subdocument = DocX.Load( "test.docx" );
var template = DocX.Create( "output.docx" );
Paragraph bookmarkParagraph = template.InsertParagraph();
foreach( var par in subdocument.Paragraphs )
{
if( par.Hyperlinks.Count > 0 )
{
Paragraph paragraph = template.InsertParagraph();
I was using the InsertParagraphAfterSelf method of Paragraph to insert paragraphs from one document to another without issues until release 2.4 (including 2.4.1), but the code is now throwing an error if I update DocX to 2.5.0 or the latest 3.0.0
The release notes of 2.5.0 state:
Is there a chance there is a regression?
My code (edited) is next; InsertParagraphAfterSelf(paragraph) is successful the first time, but the next iteration always throws the above-referenced error.
Thanks!
The text was updated successfully, but these errors were encountered: