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

Error on PrintPreview

8 Answers 147 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Daní
Top achievements
Rank 1
Daní asked on 17 Mar 2011, 06:48 PM
Hello,

Since the upgrade to Q1 2011 release, I'm getting an exception when calling PrintPreview() method, exception details:

Exception Type : InvalidOperationException
Exception Message: There is no DocumentFormatProvider which supports html
Call Stack:  a Telerik.Windows.Controls.RadRichTextBox.HtmlPrint(String title, Boolean preview)
   a Telerik.Windows.Controls.RadRichTextBox.PrintPreview()
   a UIAssistencial.Patient.ClinicalCourse.AnnViewer.ViewModel.PrintingHelper.ExpandAnnotations(AnnotationsViewerViewModel annotationsViewerViewModel)

I have a reference to Telerik.Windows.Documents.FormatProviders.Html

8 Answers, 1 is accepted

Sort by
0
Tony
Top achievements
Rank 1
answered on 17 Mar 2011, 11:10 PM
Hi

I am also getting this error. i am using the Q3 version 2010.3.1314.1040. I have referenced the HTML format provider, and added a using statement to it. The following code works:
IDocumentFormatProvider provider = new HtmlFormatProvider();
             using (MemoryStream output = new MemoryStream())
            {
 
                provider.Export(radRichTextBox1.Document, output);
   
                output.Position = 0;
                StreamReader reader = new StreamReader(output);
 
                html = reader.ReadToEnd();
                output.Close();

However this code does not, on the same page:

this.radRichTextBox1.PrintPreview();

0
Daní
Top achievements
Rank 1
answered on 21 Mar 2011, 01:03 PM
Hello,


Any word about this issue?
0
Accepted
Iva Toteva
Telerik team
answered on 21 Mar 2011, 02:42 PM
Hi Tony, Daní,

Are you by any chance using library caching? That would explain the behavior you are observing.
RadRichTextBox uses MEF in order to load all types, including format providers. When library caching is turned on, MEF tries to find types in assemblies which are still on the server. Thus it fails to find the types. When you instantiate a type explicitly, as in Daní's code snippet, everything works fine.
You can workaround the problem by registering the format providers as follows:

DocumentFormatProvidersManager.RegisterFormatProvider(new HtmlFormatProvider());

This has to be done once only, for example in the constructor of the main page.
Since all dialogs that RadRichTextBox uses are also loaded through MEF, you should instantiate them explicitly, like we do in our online MSWord demo in the constructor of the MsWordExample. (You can view the code of the demo by switching the tab from the top-right corner.)
Hope that answers the question. Let us know if library caching is not the case.

Regards,
Iva
the Telerik team
0
Daní
Top achievements
Rank 1
answered on 21 Mar 2011, 04:32 PM
Hi Iva,

The solution you propose is running for me. This issue appeared just after upgrading to Q1 2011 release, It was working fine till then. I'm not enabling library caching, but I'm using a pluggin technology taking profit of MEF. That means that when application starts, it ask to server for the list of allowed modules and then, using MEF DeploymentCatalogs, it downloads the xap files containing modules. As all modules are using Telerik assemblies, main application contains all necessary common assembleis (including Telerik's ones), so modules are compiled setting all their references CopyLocal propery set to "False"to minimize the bandwith required. I'm not sure, but as I'm using intensevely MEF and I'm using DeplymentCatalogs, maybe something changed in this new telerik release that prevents HtmlFormatProvider to be loaded in such scenarios.

Thanks.
0
Ivailo Karamanolev
Telerik team
answered on 23 Mar 2011, 02:13 PM
Hello Daní,

There were changes introduced in Q1 2011 in the way we load assemblies, namely, we have replaced parts of MEF's loading mechanism with our own. This is to avoid issues many clients encountered where some references wouldn't load and would break the entire application. We haven't encountered any issues with it yet, but obviously, the behavior is different in complicated scenarios as yours. We're glad the explicit mechanism worked in your case.

Best wishes,
Ivailo
the Telerik team
0
Tony
Top achievements
Rank 1
answered on 24 Mar 2011, 04:23 AM
This worked for me:

DocumentFormatProvidersManager.RegisterFormatProvider(newHtmlFormatProvider());


Thanks very much

0
gao
Top achievements
Rank 1
answered on 31 Aug 2011, 03:50 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;
            }
        }
    }


0
Iva Toteva
Telerik team
answered on 31 Aug 2011, 05:25 PM
Hi Gao,

Please refer to the other forum thread you posted your question in: http://www.telerik.com/community/forums/silverlight/richtextbox/throw-execptions-in-documentformatprovidersmanager.aspx.

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

Tags
RichTextBox
Asked by
Daní
Top achievements
Rank 1
Answers by
Tony
Top achievements
Rank 1
Daní
Top achievements
Rank 1
Iva Toteva
Telerik team
Ivailo Karamanolev
Telerik team
gao
Top achievements
Rank 1
Share this question
or