This project is read-only.
1
Vote

NullReferenceException in get_CanUndo()

description

Every so often when enabling the HTML editor control, property getter for CanUndo throws a NullReferenceException.

Here is an example stack trace from an application:

System.NullReferenceException: Object reference not set to an instance of an object.
at ZetaHtmlEditControl.HtmlEditControl.get_CanUndo()
at ZetaHtmlEditControl.HtmlEditUserControl.updateButtons()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.TabControl.UpdateTabSelection(Boolean updateFocus)
at System.Windows.Forms.TabControl.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.TabControl.WmSelChange()
at System.Windows.Forms.TabControl.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Note that there is no interaction with the control. I am going to take a quick look at the code and see if there is an obvious missing check to avoid this. Will add more detail if necessary.

comments

wernervd wrote Nov 9, 2013 at 4:52 PM

It's obviously the DomDocument object that is still null. Looking at other properties like CanOrderedList and CanOutdent etc, they all check that the DomDocument object is not null first before accessing it.

wernervd wrote Nov 9, 2013 at 4:58 PM

I was going to submit a patch but the SVN URL is not working for ().

Although it should be obvious enough, here is the code to update the CanUndo property to match all the others and avoid the exception:

public bool CanUndo
{
get
{
    return Document != null && (Enabled &&
                                        ((HTMLDocument)Document.DomDocument).queryCommandEnabled(@"Undo"));
}
}