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

RtfDataProvider Exception

6 Answers 288 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Jaghathish
Top achievements
Rank 1
Jaghathish asked on 04 May 2016, 09:47 AM

Hello,

I have a custom control that hosts a RichTextBox/RtfDataProvider in WPF 4.5.

I'm using Telerik version 2015.3.1104.45.

Following is the XAML which works fine in the visual studio designer.

 

<telerik:RtfDataProvider x:Name="RtfProvider"             Grid.Row="1" 
            Rtf="{Binding RtfFileContent, ElementName=RtfEditorUC, Mode=TwoWay}" 
            RichTextBox="{Binding ElementName=radRTB}" />         <telerik:RadRichTextBox x:Name="radRTB" 
                                Grid.Row="1" 
                                DocumentInheritsDefaultStyleSettings="True" 
                                IsSpellCheckingEnabled="False"                                  
                                LayoutMode="Paged" VerticalAlignment="Top" 
                                IsReadOnly="{Binding IsRtfReadOnly, ElementName=RtfEditorUC, Mode=TwoWay}"/>

 

However, at runtime, I have the following crash :

 

System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.Windows.Markup.XamlParseException: L'invocation du constructeur sur le type 'Telerik.Windows.Documents.FormatProviders.Rtf.RtfDataProvider' qui correspond aux contraintes de liaison spécifiées a levé une exception. ---> System.ArgumentNullException: La valeur ne peut pas être null.
Nom du paramètre : formatProvider
   à Telerik.Windows.Documents.FormatProviders.DataProviderBase..ctor(ITextBasedDocumentFormatProvider formatProvider, DependencyProperty stringProperty)
   à Telerik.Windows.Documents.FormatProviders.Rtf.RtfDataProvider..ctor()
   à System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.InvokeDelegate(Action`1 action, Object argument)
   à System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CallCtorDelegate(XamlTypeInvoker type)
   à System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   à MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)

The same code was working fine in WPF 3.5 with Telerik  2012.2.912.35.

Any help appreciated.

6 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 05 May 2016, 08:21 AM
Hi Jaghathish,

The format providers in RadRichTextBox are loaded using MEF. The data providers rely on the format providers and in case they are not loaded and registered correctly by the MEF, a NullReferenceException is thrown.

There are several ways to handle this. The first I could suggest you is to change the TypeCatalog with the types you are planning to use in the application. The full list of types used in RadRichTextBox could be found in our documentation

Alternatively, you could register the format provider with the DocumentFormatProvidersManager like this:
DocumentFormatProvidersManager.RegisterFormatProvider(new RtfFormatProvider());

Hope this helps.

Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Jignesh
Top achievements
Rank 1
answered on 05 Feb 2018, 04:47 AM

System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'Telerik.Windows.Documents.FormatProviders.Rtf.RtfDataProvider' that matches the specified binding constraints threw an exception.' Line number '770' and line position '30'. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: formatProvider
   at Telerik.Windows.Documents.FormatProviders.DataProviderBase..ctor(ITextBasedDocumentFormatProvider formatProvider, DependencyProperty stringProperty)
   at Telerik.Windows.Documents.FormatProviders.Rtf.RtfDataProvider..ctor()
   at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.InvokeDelegate(Action`1 action, Object argument)
   at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CallCtorDelegate(XamlTypeInvoker type)
   at System.Xaml.Schema.XamlTypeInvoker.DefaultCtorXamlActivator.CreateInstance(XamlTypeInvoker type)
   at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at TuevSuedAP.LMS.WPFForms.Testing.FrmTestResult2.InitializeComponent()
   at TuevSuedAP.LMS.WPFForms.Testing.FrmTestResult2..ctor()
   at TuevSuedAP.LMS.WPFForms.Testing.FrmTestResults.OpenTestResultDetails()

 

Hello Telerik Team,

 

As mentioned we have tried the steps, but yet we are getting this error on XAML form. This is only happening when we have more data or loading time takes more. This is too occasionally not always the case.

 

Can you please help us to know exact reason ?

 

 

0
Jignesh
Top achievements
Rank 1
answered on 05 Feb 2018, 04:50 AM
Attached is screen shot of the error.
0
Tanya
Telerik team
answered on 07 Feb 2018, 01:51 PM
Hello Jignesh,

The error still aims that the RtfFormatProvider class cannot be loaded. Could you please ensure that you are registering it using DocumentFormatProvidersManager before the call to InitializeComponent() of the window where RadRichTextBox resides?

If this still doesn't help, I would like to ask you to share the complete declaration of the control as well as the code-behind used so I can test the exact scenario on my end.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Jignesh
Top achievements
Rank 1
answered on 16 Mar 2018, 10:29 AM

Thanks for the solution.

This actually worked for us, after implementing the solution you provided to register before initialize component it worked fine and till now that bug didn't reproduced.

Just for our knowledge, why we need to register it before initialize component ? It would be great to hear from you on this.

 

Thanking you.

0
Tanya
Telerik team
answered on 21 Mar 2018, 09:23 AM
Hi Jignesh,

I am happy to hear that everything is now working.

From the error you were getting seems like there is an issue related to the loading of the format provider. Since the format providers of RadRichTextBox are loaded through MEF, my assumption is that the framework fails to load the type, thus it is not present when needed. Using the DocumentFormatProvidersManager to register the format provider directly forces the loading without using MEF and should be always working as expected.

Hope this answers your question.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
Jaghathish
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Jignesh
Top achievements
Rank 1
Share this question
or