RadEditor - Object reference not set to an instance of an object

9 posts, 1 answers
  1. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 15 Feb 2018 Link to this post

    Hello

    I get sometimes a runtime error in production:

    Message: Object reference not set to an instance of an object.
    StackTrace:    at Telerik.Web.UI.RadEditor.<get_Text>b__b(Match m)
       at System.Text.RegularExpressions.RegexReplacement.Replace(MatchEvaluator evaluator, Regex regex, String input, Int32 count, Int32 startat)
       at System.Text.RegularExpressions.Regex.Replace(String input, MatchEvaluator evaluator)
       at System.Text.RegularExpressions.Regex.Replace(String input, String pattern, MatchEvaluator evaluator, RegexOptions options)
       at Telerik.Web.UI.RadEditor.get_Text()
       at xyz.CN_BL.cnExportMethodsBL.writeEXTFlat(List`1 toWriteInSheet, SpreadsheetDocument xlDoc, WorkbookPart workbookPart, WorksheetPart& worksheetPart, Int32 iColIndex, ExtWert extW, Stamm st, Sheet sh, UInt32& indexRow, AdminTexte at, Int32 aktSprache) in C:\Projekte\xyz\CN_BL\cnExportMethodsBL.cs:line 11826
       at xyz.CN_BL.cnExportMethodsBL.doExport(IObjectScope myScope, String& strShortenFileNameToUse, MemoryStream& mStream, Int32[] Export_Ids, Int32[] Export_IdsStamm, exportMode ExportMode, exportTyp ExportTyp, exportTyp ExportTypOriginal, Sprache aktSprache, Boolean bModulWFAktiv, Int32 FirmaId, Int32 ExportSprache, String strFileName, String& strError) in C:\Projekte\xyz\Web\CN_BL\cnExportMethodsBL.cs:line 6640
       at xyz.CN_BL.FileFunctions_BL.startExportBackground(Object Param) in C:\Projekte\xyz\Web\CN_BL\FileFunctions_BL.cs:line 1212
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart(Object obj)

    The error does not occur every time. My guess: the more data is processed, the more likely the w3wp.exe crashes, or more specific, the special export thread crashes.
    I can not reproduce the error in the development environment.

    Creation of the error:
    The user wants to export data. The web server starts a separate thread for writing datas into an excel file (via MemoryStream). Codesnippet from the export method:

    Loop, which calls the writeEXTFlat() methods multiple times

    {
    // static method writeEXTFlat()
      ... some code ...

      Line 11826:  Telerik.Web.UI.RadEditor re = new Telerik.Web.UI.RadEditor();

      ... more code without touching RadEditor ...

      foreach (int i =0; x < exportRecs; i++)
      {

         ... more code without touching RadEditor ...

         re.Content = strExportDataWithHTML;
         string strToExport = re.Text;

         ... more code without touching RadEditor ...
      }

    }

    My question : Any idea why this error can happen? It makes totaly no sense to me. strExportDataWithHTML is always at least an empty string.

    TIA
    Markus

  2. Rumen
    Admin
    Rumen avatar
    14220 posts

    Posted 15 Feb 2018 Link to this post

    Hi Markus,

    The Third party export to PDF converter, which RadEditor uses, does not support the following scenarios:
    • Image transparency
    • Right-to-left fonts
    • Nested DIV elements with absolute position
    • Nested DIV elements with specified width or height
    • Automatic text clipping
    • Client-side binding
    • Medium trust
    • non well formed tags
    • External styles and CSS in style tags


    Another limitation is that the Export to PDF library cannot export full HTML page - this means that the exported content should not contain <html>, <head> and <body> tags, but only the contents inside the <body> tags.

    Please make sure that the above requirements are satisfied. If they are, please provide the HTML content that is causing the error.

    Another alternative is to export the content using the Telerik PdfProcessing library as shown in this KB article: Using an external library for the export to PDF functionality in Telerik’s ASP.NET Editor.

    Regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 16 Feb 2018 in reply to Rumen Link to this post

    Hi Ruben

    Thanks for your answer.

    The export normally runs smooth on other systems: other production site, on the test system and on the development system, and most of the time even on the production site, where this error was caught. I be very sure, the requirements are satisfied. 

    The export does not use any of Telerik's ExportFunctionality. It uses the OpenXML-SDK to export to Excel (not PDF). The RadEditor is just there to remove the HTML-Tags.

    As I said, I can not reproduce the error on the development system even with exactly the same text content (not in the exact same method, but in a similar test-method. I can't get the whole DB from the client to run exactly the same scenario). So I am not able to point out, which content may causes the problem. And I assume the contents are not the problem. The text contents are not fully HTML-Pages. Every content is text, which was inserted earlier by users using the RadEditor.

    I can't make any sense of the Exception. How is it possible to get a NULL reference in a well created object? And the eventlog entry points to the creation of the RadEditor object, not to the lines where the editors text was referenced.
    I hoped you could may point out a scenario where a NULL reference inside the editor could cause an error. Any suggestions?

    Thanks
    Markus


  4. Rumen
    Admin
    Rumen avatar
    14220 posts

    Posted 20 Feb 2018 Link to this post

    Hi Markus,

    Usually we do not support third party export libraries, but how exactly do you obtain the RadEditor content and export it?

    Do you use the OnExportContent event of the control?
    Do you use the Content or Text properties to obtain the content?

    If you just need plain text for the export, you can set the RadEditor content to an asp:TextBox and export it from the TextBox.

    Regards,
    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 21 Feb 2018 in reply to Rumen Link to this post

    Hi Rumen

    As you see, in the bold text I posted in the first post: into the RadEditor.Content the HTML-Text is loaded and from the RadEditor.Text the no-HTML string is taken.
    I don't see anything related to a third party export tool, it's just a normal input-output procedure like discribed in your documentation to remove the HTML-Tags.

    I don't expect you to solve this problem. But I hoped to hear any idea or point me a direction, why this Null-Pointer Exception can happen. Please have a look into the RadEditor SourceCode and find out, if there are any possibilities this error can occure, and if you find something, let me know which circumstance could cause this error. Thank you!

    Best regards
    Markus

  6. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 23 Feb 2018 in reply to Markus Link to this post

    Hi Rumen

    I could track down the problem:
    Code: 
    1) RadEditor.Content = "input text";

    2) string strOutput = RadEditor.Text;

    The problem is, when used with a large text (7087 characters) (or may some characters in it?) RadEditor.Text throws a NULL-Exception.
    The first reference to .Text throws an Error. If I reference .Text a second time (after the Exception), the .Text is available. It doesn't matter how long I wait between putting the input text into .Content and accessing the .Text value. I always get the Exception first. After this exception, the .Text is available for further processing.

    And idea how to handle this? (I can wrap this into a try/catch and access .Text in the catch a second time, that works. But is there a better solution?]

    Thanks
    Markus

  7. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 23 Feb 2018 in reply to Markus Link to this post

    Let's clarify this:
    It only happens, when a separate thread is created by the Web-Server. If the conversion happens in the main w3wp.exe, no error occurs.
    I attached the text file as .png file. Please rename it after download (if this works)

    Thanks
    Markus
  8. Answer
    Rumen
    Admin
    Rumen avatar
    14220 posts

    Posted 26 Feb 2018 Link to this post

    Hi Markus,

    Thank you for the extra information.

    The error is most likely caused by that RadEditor is not added to the form and its control life cycle does not pass correctly.

    What you can try is:
    • Add RadEditor to an ASP.NET Panel in the Form and hide the panel with style="display:none". If the problem still persists, you will need to go through the content and find exactly which character or portion of the content is breaking the regular expressions of the Text property.
    • or use some HTML to Text converter library to do the conversion. For example HtmlAgilityPack as suggested in StackOverflow - How can I strip HTML tags from a string in ASP.NET?
    • or use a regular expression to strip the HTML tags: 
       
      Regex.Replace(htmlText, "<.*?>", string.Empty);

      This way you want need to initialize a heavy ASP.NET component specialized for HTML WYSIWYG editing and creation for the purposes of HTML to Text conversion.

    Best regards,

    Rumen
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Markus
    Markus avatar
    36 posts
    Member since:
    Dec 2008

    Posted 01 Mar 2018 in reply to Rumen Link to this post

    Hi Rumen

    Thanks for the suggestions.

    Best regards
    Markus
Back to Top