DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Crash when merging DOCX files without custom properties

Open halfs2 opened this issue 8 months ago • 1 comments
trafficstars

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?"

halfs2 avatar Mar 10 '25 21:03 halfs2

Hi, Thank you for reporting this. This issue will be fixed in the next release. FYI, the minimum value for pid must be 2. Thank you

XceedBoucherS avatar Mar 11 '25 11:03 XceedBoucherS