This project has moved. For the latest updates, please go here.

Null Reference Exception

Sep 1, 2011 at 8:31 PM
Edited Sep 1, 2011 at 8:33 PM

Hello,

I'm wondering if you'd be kind enough to address an issue I'm having. I'm getting a null reference exception when calling converter.Parse().

While I haven't stepped through your code, the problem appears to be caused by poorly formed HTML. Specifically, it contains some table rows outside of any table definition. The error almost certainly occurs near the end of ProcessTableRow(), on the line tables.CurrentTable.Append(row), since there will be no table at this time.

I know the input is not valid, but sometimes users give us bad data and there should be some type of recovery. It doesn't matter to me if the data is discarded altogether, but I'd like to avoid it throwing a general exception like this.

Error Details:

System.NullReferenceException occurred
  Message=Object reference not set to an instance of an object.
  Source=HtmlToOpenXml
  StackTrace:
       at NotesFor.HtmlToOpenXml.TableContext.get_CurrentTable()
       at NotesFor.HtmlToOpenXml.HtmlConverter.ProcessTableRow(HtmlEnumerator en)
       at NotesFor.HtmlToOpenXml.HtmlConverter.ProcessHtmlChunks(HtmlEnumerator en, String endTag)
       at NotesFor.HtmlToOpenXml.HtmlConverter.Parse(String html)
       at VIP.Web.ViperSite.Programs.Proposals.ProposalDocumentBuilder.RenderTextOnly(ArticleSection section)
in C:\Users\Jonathan\Documents\Viperrunk\ViperSite\Programs\ProposalDocument\ProposalDocumentBuilder.cs:line 562

I've also posted my input data at http://www.softcircuits.com/Client/HtmlExample.txt.

Your assistance would be greatly appreciated.

Thanks.

Coordinator
Sep 5, 2011 at 12:32 PM

hello,

this error has been fixed with my last checkin.
You can download the last changeset here.

Sep 16, 2011 at 3:27 PM
Edited Sep 16, 2011 at 3:52 PM

Thanks. But it looks like it hasn't been posted yet. The latest update only shows the fixes for null-reference exceptions when missing table context.

Has the change just not been uploaded yet?

Thanks again.

Coordinator
Sep 16, 2011 at 4:00 PM
Edited Sep 27, 2011 at 1:26 PM

Hello,

I'm sorry, I'm quite busy at these time.
I wanted to test your changes (about Code Updates You May Consider) with a more complicated example (rowspan and columnspan) but I'm lack time.

As you are very active with the library, do you want to become a member of this project ?

Sep 16, 2011 at 7:46 PM

I apologize. When I wrote the response above, I thought you had replied to my more recent question. (Somehow, I saw this discussion at the top of the list.)

I'm doing the work for a client and so I have no idea how much work I'll do with the library. But I'd be happy to contribute any changes I do make. If that's worth setting me up as a member of the project, I'd be happy to do that.

But, if you do get a little time, I could use some insight as to why, when a table cell contains <p> tags, extra paragraphs are inserted into the cell in Word. Looking over the code, I still haven't quite figured that out.

Thanks.