Skip to content

Crash when merging DOCX files without custom properties #485

@halfs2

Description

@halfs2

I'm encountering an error when merging DOCX files. The exception thrown is System.InvalidOperationException: Sequence contains no elements, which happens with some files I add to the merge list.

I downloaded the source code to investigate the issue, and it turns out that the files causing the problem apparently do not have custom properties, leading to an error in this block:

`IEnumerable pids =
(
from d in remote_custom_document.Root.Descendants()
where d.Name.LocalName == "property"
select int.Parse( d.Attribute( XName.Get( "pid" ) ).Value )
);

int pid = pids.Max() + 1;`

I fixed the issue by checking if pids contains any elements and setting the value to 1 if it doesn't:

int pid = pids.Any() ? pids.Max() + 1 : 1;

I don't know much about the internal structure of DOCX files, so I’d like to ask: Is this fix valid? If so, should I submit a PR to fix it?"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions