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

NullReference exception using XAMLFormatProvider.export

8 Answers 128 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Guillaume
Top achievements
Rank 1
Guillaume asked on 29 Mar 2013, 04:16 PM
Hi,

We are trying to save a RadDocument into the XAML format.
So, we have add a test button to our UI in order to manage the save.

Unfornutaly, we've got the following exception during the call of the export method :

-  ex    {System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel. ---> System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
   à Telerik.Windows.Documents.Model.RadDocument.get_LineSpacing()
   --- Fin de la trace de la pile d'exception interne ---
   à System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   à System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   à System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   à Telerik.Windows.Documents.FormatProviders.Xaml.XamlWriter.WriteProperties(Object obj)
   à Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.WriteXaml(Boolean isStylesheet, Object objectToWrite, XamlWriter xamlWriter, Boolean isRoot)
   à Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Export(RadDocument document)
   à Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Export(RadDocument document, Stream output)
   à Arcan.Windows.MainPage.GetXamlFormDocument(RadDocument document)
   à Arcan.Windows.MainPage.RadSave(Object sender, RoutedEventArgs e)}    System.Reflection.TargetInvocationException

The save method is implemented as follow :

try{
// Save as XAML
string xaml = GetXamlFrmDocument(this.radRichTextBox.Document);
     ...

} catch (System.Reflection.TargetInvocationException ex) {
HtmlPage.Window.Alert(ex.Message);
}

The implementation of the GetXamlFromDocument method is as follow :

       
public static string GetXamlFormDocument(RadDocument document)
{
    IDocumentFormatProvider exporter = new XamlFormatProvider();
    string result;
    using (MemoryStream stream = new MemoryStream())
    {
        exporter.Export(document, stream);
        stream.Seek(0, SeekOrigin.Begin);
        StreamReader reader = new StreamReader(stream);
        result = reader.ReadToEnd();
    }
    return result;
}

Thanks ins advance for any help.

Best regards

Guillaume Chomat

8 Answers, 1 is accepted

Sort by
0
Tuo
Top achievements
Rank 1
answered on 01 Apr 2013, 05:29 PM
I got the same exception too.
0
Petya
Telerik team
answered on 03 Apr 2013, 11:27 AM
Hello Guillaume, Tuo,

Unfortunately, I cannot replicate the behavior you are observing. I tried setting different values for the line spacing property of several paragraphs and exporting the document, but could not cause an exception.

It would be helpful if you can send us some steps to reproduce or even better, open a support ticket and send us a document that can be used for troubleshooting.
 
All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Guillaume
Top achievements
Rank 1
answered on 03 Apr 2013, 12:38 PM
NB : the code is executed into the click event handler. if i'm using the same code int the UI thread i haven't any error.
0
Petya
Telerik team
answered on 05 Apr 2013, 02:26 PM
Hi Guillaume,

Unfortunately, this is a known issue with RadDocument, caused by the fact that in the current implementation the creation of some document elements involves the creation of tte respective UI elements. We have plans to improve the off-thread creation and modification of documents and allow usage of the format providers in multi-threading scenarios, but for now it's not clear when this will be implemented. Until then, your only option is to use RadDocument in STA thread.

I am sorry for the inconvenience.

All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Guillaume
Top achievements
Rank 1
answered on 17 Apr 2013, 01:06 PM
Do you have a sample how to call the code into STA ?
I've tried but with the same exception :

System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
            {
                //Call your Middlewire code like service calling, db operations etc.
 
            })).ContinueWith(task => {
                //Call your Middlewire code like service calling, db operations etc.
 
            }) :
0
Petya
Telerik team
answered on 19 Apr 2013, 04:38 PM
Hello Guillaume,

The code should look like this:
Thread thread = new Thread(() =>
{              
    // import/export
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

Let us know if you are still facing difficulties.
 
Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Robert
Top achievements
Rank 1
answered on 19 Oct 2013, 01:24 AM
Hi,

I'm also getting an error when exporting my document to XAML.
I've been playing with paragraph and span styles and I suspect something there is causing the problem as it used to work fine.

I get a NULL Reference exception and my stack trace is as follows:
   at Telerik.Windows.Documents.Model.RadDocument.get_LineSpacing() in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\RadDocument.cs:line 749

Any ideas how I can fix this or what is causing this?

Thanks,

Rob
0
Petya
Telerik team
answered on 23 Oct 2013, 11:03 AM
Hi Rob,

I believe we addressed the observed issue in the support ticket you opened on the matter. If you have any additional feedback in this regard, feel free to contact us again.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Guillaume
Top achievements
Rank 1
Answers by
Tuo
Top achievements
Rank 1
Petya
Telerik team
Guillaume
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or