The "Item has already been added. Key in dictionary" error after upgrading to v12

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v12)  /  Re: The "Item has already been added. Key in dictionary" error after upgrading to v12

DynamicPDF CoreSuite for .NET (v12) Forum

Hello,

I have upgraded DynamicPDF from v8.0 to DynamicPDF.Core v12. I have a license for v8.0 and I am using an evaluation license for v12 for now. When I merge two of the same pdf files, certain files produce the error below. This does not occur on v8.0. How can I resolve this and merge the pdf files without an exception? Here's the sample code.

Error: Item has already been added. Key in dictionary: 'h.uaew7y1ilnx8'  Key being added: 'h.uaew7y1ilnx8'

            try
            {
                // Add documents to merge
                var mergedoc = new MergeDocument();
                mergedoc.Append(@"c:\temp\source.pdf");
                mergedoc.Append(@"c:\temp\source-copy.pdf");
                mergedoc.Draw(@"c:\temp\output.pdf");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


Thank you,
---mk

Posted by a ceTe Software moderator
Hello,

If you are merging the same PDF file multiple times then it is suggested to load the source PDF using PdfDocument object and then use this for appending to MergeDocument object.

Here is a code sample.

            try
            {
                PdfDocument pdfDoc = new PdfDocument(@"c:\temp\source.pdf");
                // Add documents to merge
                var mergedoc = new MergeDocument();
                mergedoc.Append(pdfDoc);
                mergedoc.Append(pdfDoc);
                mergedoc.Draw(@"c:\temp\output.pdf");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

If you continue facing any issue then please send over the following information to support@dynamicpdf.com so we can look into it further.

1. Source PDFs using which we can recreate the issue.
2. Full error message along with stack trace.
3. Exact version and build number of DynamicPDF Core Suite DLL file used in your application. You can find this information by right clicking on the DynamicPDF Core Suite DLL file>>Properties>>Details tab>>Product version. Take a screenshot of Details tab and send it over to us.

Thanks,
ceTe Software Support Team

All times are US Eastern Standard time. The time now is 1:15 PM.