Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

New bug in ApplyTemplate method after V2.1.0 released

Đang mở
#445 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C#
Star
1.9k
Fork
482
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của xceedsoftware/DocX

Tất cả issue của xceedsoftware/DocX

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.