Hi,
I'm writing a custom control and I face a strange problem since I have
the latest release of Visual C# express 2005.
When I drag the control from the toolbox to a form, I get this
exception:
Failed to create component. The error message follows:
'System.NullReferenceException: Object reference not set to an instance
of an object. at
System.Windows.Forms.NativeWindow.AddWindowToTable(IntPtr handle,
NativeWindow window) at
System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean
ssignUniqueID) at
System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle) at
System.Windows.Forms.Design.ControlDesigner.ChildSubClass..ctor(ControlD
esigner designer, IntPtr hwnd) at
System.Windows.Forms.Design.ControlDesigner.HookChildHandles(IntPtr
firstChild) at
System.Windows.Forms.Design.ControlDesigner.HookChildControls(Control
firstChild) at
System.Windows.Forms.Design.ControlDesigner.OnHandleChange() at
System.Windows.Forms.Design.ControlDesigner.DesignerWindowTarget.OnHandleChange(IntPtr
newHandle) at
System.Windows.Forms.Control.ControlNativeWindow.OnHandleChange() at
System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean
assignUniqueID) at
System.Windows.Forms.NativeWindow.AssignHandle(I...'
But if I build (for the first time) the entire solution, I can drag the
control without any error. Then if I drag a second one, I get the
exception again. If I rebuild it will be fine, and so on... Sometimes I
can drag 2 controls with no error and will need a recompile for the 3rd
one.
I have no idea where to search and especially how to debug that with C#
express.
Any idea ?
Thank you for your help
Montezuma - 28 Nov 2005 09:44 GMT
Hi,
your control is trying to evaluate a property or an object which is null.
I understand your disorientation, and honestly i don't get why those errors
that one gets in the design surface don't show the relative line directly.
You can find the line generating the error in the Error List, among the
Warnings. Well, weren't we talking about errors?...
By the way, according to my experience, the line reported is even the wrong
one, so you should check the behavior caused by the previous one.
Hope this helps.
Montezuma
> Hi,
>
[quoted text clipped - 38 lines]
>
> Thank you for your help
jokiz - 02 Dec 2005 10:13 GMT
you should debug the IDE instance you are dragging these controls with
another IDE...