DocX
DocX copied to clipboard
Crash when merging DOCX files without custom properties
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
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?"
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