We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

AppendHtml throws nullreferenceexception

DocIO throws nullreference exception when I try to append Html content to a paragraph.
I am near deadline, which version is working?

  a következő helyen: Syncfusion.DocIO.DLS.HTMLConverterImpl.AppendToTextBody(ITextBody textBody, String html, Int32 paragraphIndex, Int32 paragraphItemIndex)
   a következő helyen: Syncfusion.DocIO.DLS.HTMLConverterImpl.AppendToTextBody(ITextBody textBody, String html, Int32 paragraphIndex, Int32 paragraphItemIndex, IWParagraphStyle style, ListStyle listStyle)
   a következő helyen: Syncfusion.DocIO.DLS.WParagraph.AppendHTML(String html)
   a következő helyen: Controllers.HomeController.Index() hely: HomeController.cs, sor: 324
   a következő helyen: lambda_method(Closure , ControllerBase , Object[] )
   a következő helyen: System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   a következő helyen: System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   a következő helyen: System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   a következő helyen: System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   a következő helyen: System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_0.b__0()
   a következő helyen: System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_2.b__2()

EDIT: additional info, the code:

var par = new WParagraph(wordDocument);
par.AppendHTML(Content);

Thanks,
 Peter

5 Replies

MJ Mohanaselvam Jothi Syncfusion Team May 16, 2019 05:19 AM UTC

Hi Peter,

Thank you for contacting Syncfusion support.

From the given details, we suspect that the issue might be specific to the HTML content used at your end. So, could you please share us the HTML content which used at your end. Thereby, we will check on the reported problem and provide you the solution at the earliest.

Note: If you have any confidential data in you HTML,
you can also mail the file to our Syncfusion support through support@syncfusion.com.

Regards,
Mohanaselvam J



PN Péter N May 16, 2019 07:29 AM UTC

Thank you for the response. You can try this:

using Syncfusion.DocIO.DLS;

namespace DocIONull
{
    class Program
    {
        static void Main(string[] args)
        {
            WordDocument document = new WordDocument();
            document.EnsureMinimal();
            document.AddSection().AddParagraph().AppendText("#TEST#");
            IWParagraph paragraph = new WParagraph(document);
            paragraph.AppendHTML("<p>NullReferenceException</p>");
            TextBodyPart bodyPart = new TextBodyPart(document);
            bodyPart.BodyItems.Add(paragraph);
            document.Replace("#TEST#", bodyPart, true, true);
            document.Save("null.docx");
        }
    }
}



MJ Mohanaselvam Jothi Syncfusion Team May 16, 2019 09:11 AM UTC

Hi Peter,

Thank you for sharing us the details.

When appending HTML content in paragraph, the HTML content may contain multiple paragraphs, tables or other body items. Essential DocIO appends the HTML contents (multiple paragraphs, tables) following with the current paragraph in body of Word document, which is one of the behavior in appending HTML contents. The reported problem occurs due to appending new paragraph (from HTML content) with the paragraph which doesn’t linked with the body of the Word document.


To append the HTML with Word document, we suggest you to append the HTML contents after linked with body of the Word document. Thus, it appends the body items along with existing body items in the TextBodyPart properly. Please refer the below highlighted code example to resolve the problem at your end:
 
WordDocument document = new WordDocument(); 
document.EnsureMinimal(); 
document.AddSection().AddParagraph().AppendText("#TEST#"); 
IWParagraph paragraph = new WParagraph(document); 
TextBodyPart bodyPart = new TextBodyPart(document); 
bodyPart.BodyItems.Add(paragraph); 
paragraph.AppendHTML("<p>NullReferenceException</p>"); 
document.Replace("#TEST#", bodyPart, true, true); 
document.Save("null.docx"); 


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



PN Péter N May 16, 2019 11:01 AM UTC

Thank you!

Suggestion:
Handle this situation and throw InvalidOperationException("Any helpfull message") when someone tries to append HTML before the paragraph attached.

Regards,
 Peter


MJ Mohanaselvam Jothi Syncfusion Team May 17, 2019 11:55 AM UTC

Hi Peter,

Thank you for your suggestions. We will consider your feedback as a valid request and will handle this scenario.
We don’t have any immediate plans to implement this at our end. We will implement this in any of our upcoming releases.

Please let us know if you have any other questions.
 
 
Regards, 
Mohanaselvam J 


Loader.
Live Chat Icon For mobile
Up arrow icon