This is a migrated thread and some comments may be shown as answers.

Throw Execptions in DocumentFormatProvidersManager

3 Answers 82 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
gao
Top achievements
Rank 1
gao asked on 31 Aug 2011, 04:41 PM
I had this problem with codes below:
The system caught this execption: (System.ArgumentException:. Has been added with the same key entry)
:
 System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
System.Collections.Generic.Dictionary`2.System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.Add(KeyValuePair`2 keyValuePair)
 Telerik.Windows.Documents.FormatProviders.DocumentFormatProvidersManager.RegisterFormatProvider(IDocumentFormatProvider provider)
 ProjectManagePlatform.UI.Common.ExamplesFormatProvidersManager.RegisterFormatProviders()}

When the system runs in if{} shown below, it throws the execption.

Codes Below:
using Telerik.Windows.Documents.FormatProviders;
using Telerik.Windows.Documents.FormatProviders.Html;
using Telerik.Windows.Documents.FormatProviders.OpenXml.Docx;
using Telerik.Windows.Documents.FormatProviders.Pdf;
using Telerik.Windows.Documents.FormatProviders.Txt;
using Telerik.Windows.Documents.FormatProviders.Xaml;

public static class ExamplesFormatProvidersManager
    {
        private static bool isRegistered = false;

        /// <summary>
        /// This method is used only to work around limitations for using MEF in Examples.
        /// </summary>
        public static void RegisterFormatProviders()
        {
            if (!isRegistered)
            {
                DocumentFormatProvidersManager.RegisterFormatProvider(new XamlFormatProvider());
                DocumentFormatProvidersManager.RegisterFormatProvider(new HtmlFormatProvider());
                DocumentFormatProvidersManager.RegisterFormatProvider(new DocxFormatProvider());
                DocumentFormatProvidersManager.RegisterFormatProvider(new TxtFormatProvider());
                DocumentFormatProvidersManager.RegisterFormatProvider(new PdfFormatProvider());

                isRegistered = true;
            }
        }
    }


3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 31 Aug 2011, 05:23 PM
Hello Gao,

By default, the format providers are loaded through MEF, so you don't need to register them. As the summary of the method says, the RegisterFormatProvider method is used only in the cases when MEF does not work, e.g. when library caching is enabled.
If you are not using library caching, you can just skip this registration. The other solution would be to check explicitly if the format providers have been loaded (using the DocumentFormatProvidersManager.FormatProviders property), but that is hardly necessary.

Kind regards,
Iva
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Roberto Pantalena
Top achievements
Rank 1
answered on 20 Dec 2011, 03:01 PM
Hi, I need to simulate the example of TelerikEditor and if i write this line like in the example, it doesen't work

 
ExamplesFormatProvidersManager.RegisterFormatProviders(); 
 
I think because I use prism..Is there a way to implement this with prism? (if i remove this line of code it works, but it doesen't open word, xaml and pdf documents)
0
Iva Toteva
Telerik team
answered on 22 Dec 2011, 07:49 PM
Hi Roberto,

From the ticket you opened, it turned out that the problem is due to the fact that you are using Prism and the assemblies containing the format providers were not referenced in the project where you are showing the view with RadRichTextBox.
Adding the references in the other project should have solved the issue. We will also make sure to update the documentation on this topic.

Regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
gao
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Roberto Pantalena
Top achievements
Rank 1
Share this question
or