Throw Execptions in DocumentFormatProvidersManager

4 posts, 0 answers
  1. gao
    gao avatar
    6 posts
    Member since:
    Nov 2010

    Posted 31 Aug 2011 Link to this post

    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;
                }
            }
        }


  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 31 Aug 2011 Link to this post

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

  3. Roberto Pantalena
    Roberto Pantalena avatar
    19 posts
    Member since:
    Jul 2009

    Posted 20 Dec 2011 Link to this post

    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)
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 22 Dec 2011 Link to this post

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

Back to Top