Docx Import returns Error: System.ArgumentException: 'An item with the same key has already been added. Key: 0'

1 Answer 247 Views
PdfProcessing WordsProcessing
Christopher
Top achievements
Rank 1
Christopher asked on 18 Oct 2022, 07:58 AM

Hello,

we are currently in need for a docx to pdf converter.

The docx file contains placeholders created in word. When we want to read it in with the Telerik documents package it gives us an error. 

The Import() function returns:

Error: System.ArgumentException: 'An item with the same key has already been added. Key: 0'

Here is the code we are using:

        static void ConverDocxToPdf(string path, string resultPath)
        {
            var docxPRovider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
            var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();

            byte[] docBytes = File.ReadAllBytes(path);
            var document = docxPRovider.Import(docBytes);

            var resultBytes = pdfProvider.Export(document);
            File.WriteAllBytes(resultPath, resultBytes);
        }

 

I attached one of the templates we are using. When you try to read it in, it will return the mentioned error.

 

Thank you in advance!

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 19 Oct 2022, 07:58 AM

Hello Christopher,

This is a known issue that is already logged on our feedback portal. You can track its progress, subscribe to status changes, and add your comment to it here: WordsProcessing: Cannot properly import a document that has duplicating xml definitions in the original and glossary documents

I am afraid I cannot suggest a workaround for this.

I want to apologize for the inconvenience this issue is causing you.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Andre
Top achievements
Rank 1
commented on 20 Jan 2026, 08:50 PM

@Dimitar Is this still the case? Have there not been any fixes for this?
Yoan
Telerik team
commented on 21 Jan 2026, 01:13 PM

Hello Andre,

The task in question remains unplanned, however, on its public page, you can find a temporary workaround you can try. It deletes all the glossary files before importing the document in order to avoid conflicts:

string path = "File.docx";
using (Stream str = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
	using (ZipArchive archive = ZipArchive.Update(str, null))
	{
		foreach (ZipArchiveEntry entry in archive.Entries.ToList())
		{
			if (entry.FullName.Contains("glossary/"))
			{
				entry.Delete();
			}
		}
	}

	DocxFormatProvider provider = new DocxFormatProvider();
	RadFlowDocument flowDocument = provider.Import(str, null);
}

We prioritize the tasks in our Feedback Portal by taking into consideration various factors like demand, complexity, capacity, etc. We are doing everything in our power to answer customer requests and needs by resolving these tasks as fast as possible, but some receive less attention than others, which is why they can sometimes be delayed and left unplanned.

The best I can offer is to subscribe to the task so you can track its status via notifications. Whenever it's status changes for any reason, we update its public page, which automatically notifies our customers who are subscribed to it.

I hope this helps.

Regards,

Yoan

Tags
PdfProcessing WordsProcessing
Asked by
Christopher
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or