NullReference exception using XAMLFormatProvider.export

9 posts, 0 answers
  1. Guillaume
    Guillaume avatar
    5 posts
    Member since:
    Mar 2013

    Posted 29 Mar 2013 Link to this post

    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

  2. Tuo
    Tuo avatar
    20 posts
    Member since:
    Oct 2011

    Posted 01 Apr 2013 Link to this post

    I got the same exception too.
  3. DevCraft banner
  4. Petya
    Admin
    Petya avatar
    975 posts

    Posted 03 Apr 2013 Link to this post

    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.

  5. Guillaume
    Guillaume avatar
    5 posts
    Member since:
    Mar 2013

    Posted 03 Apr 2013 Link to this post

    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.
  6. Petya
    Admin
    Petya avatar
    975 posts

    Posted 05 Apr 2013 Link to this post

    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.

  7. Guillaume
    Guillaume avatar
    5 posts
    Member since:
    Mar 2013

    Posted 17 Apr 2013 Link to this post

    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.
     
                }) :
  8. Petya
    Admin
    Petya avatar
    975 posts

    Posted 19 Apr 2013 Link to this post

    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.

  9. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 18 Oct 2013 Link to this post

    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
  10. Petya
    Admin
    Petya avatar
    975 posts

    Posted 23 Oct 2013 Link to this post

    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 >>
Back to Top
DevCraft banner