Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

New bug in ApplyTemplate method after V2.1.0 released

Abierto
#445 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
1.9k
Forks
482
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de xceedsoftware/DocX

Todos los issues de xceedsoftware/DocX

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.