New bug in ApplyTemplate method after V2.1.0 released
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start at ApplyTemplate(Stream templateStream, bool includeContent) and reproduce the failure with the provided code using a DOCX containing an empty paragraph. Read the Paragraphs collection behavior and paragraph.Remove(false), especially RemoveParagraphFromCache; done means ApplyTemplate with includeContent set to false completes without InvalidOperationException.
Written by the indexing model from the issue text.
Description
Hello,
My old code stopped working after I updated nuget package from V2.0.0 to V2.3.0. The reason is that ApplyTemplate( Stream templateStream, bool includeContent ) method now throws an System.InvalidOperationException when includeContent is set to false because of those reasons:
if( !includeContent )
{
foreach( Paragraph paragraph in this.Paragraphs )
{
paragraph.Remove( false );
}
}
In this part of ApplyTemplate method paragraph.Remove( false ); modifies Paragraphs collection, and this causes foreach-loop to break. This is happening because in V2.1.0 (commit 9c431afb) realization of Paragraphs collection was changed and now there is underlying List<Paragraph> _editableParagraphsCollection list which is modified when paragraph.Remove( false ); calls RemoveParagraphFromCache( paragraph );
The code to reproduce the bug is as simple as that:
using (var document = DocX.Create("test.docx"))
{
using (var templateStream = new FileStream("template.docx", FileMode.Open, FileAccess.Read))
{
document.ApplyTemplate(templateStream, false);
}
document.Save();
}
where template.docx is any docx created in MS Word, because even empty document includes one empty paragraph. I'm not sure which is the most accurate way to fix this issue.
- Dominant language
- C#
- Stars
- 1.9k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xceedsoftware/DocX
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
xceedsoftware/DocX#489 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
xceedsoftware/DocX#488 · 1 comment · 1 reaction ·
-
keep formatOpen
Difficulty 3/5 1-2 days Newbie friendliness 25/100
xceedsoftware/DocX#487 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
xceedsoftware/DocX#485 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
xceedsoftware/DocX#482 · 4 comments ·
All issues in xceedsoftware/DocX
Similar issues
-
[Doc Gap] Document new --enable-public-network-access breaking change for azurebackup vault createOpencopilot documentation
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
area-dashboard
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
0 - Backlog Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
BrighterCommand/Brighter#4539 ·
Maintainers usually reply within 1 day
-
area-networking
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dotnet/aspnetcore#69671 · 1 comment ·
Maintainers usually reply within 1 day
-
test
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NethermindEth/nethermind#14274 ·
Maintainers usually reply within 1 day