Designer Throwing Error

G

Guest

Hi

I am having forms that are in Design Mode, throw an custom class error, when the form is closed in the Designer. The error comes from a custom class. This class and the form are clearly not instantiated when the form is in Design Mode. How can I detect what is causing this error. The error message is "Object reference is not set to an instance object". At runtime, the forms operate without any errors being thrown. So it is quite confusing

Thanks
Mark
 
G

Guest

To clarify, the form is in the designer, in design mode and is being closed when the error occurs.
 
G

Guest

It would appear that the instance of your custom class is doing something it is supposed to do only at run time. Perhaps you should determine from your code (nothing of which you have posted) what your custom class should not be doing during design time. In case you find it doing something it should not a design time, use a discriminating code that checks if the control is being hosted in Design Mode

//in C
if(this.DesignMode)
//do somethin
}else
//do another thin


The object not being set error could creep in if it expects to do something while in the wrong host(container) runtime mode. What does your custom class do when your form closes at runtime and design time? You must find the answer to your problems when you answer that question. I believe you posted a related issue in this forum earlier..post some code.you may receive better help!
 
J

Jeremy Williams

When you display a form or a usercontrol on a form at design-time, the IDE
actually does create an instance of the form or control. So any code you
have in the constructor of the form or usercontrol will be executed.

Any code you have that might directly or indirectly call an instance of your
custom class should be moved to an event handler attached to the Load event
of the form or control. Then, wrap the code in a check for
Component.DesignTime(), as Jason mentioned. The Load event is the required
location for this code, because it is not possible to tell in the
constructor of a form or usercontrol whether DesignTime is the current
state.

Mark said:
That's the problem Jason. I don't expect the class to be doing anything
at design time. And no code has been written to directly access this custom
class during Design time. I would place a code example, except where would
I start. This is an intricate set of business object properties being used
thru a user control which is set on a Windows Form.
So from here I would ask, how does Design time even get involved in this
code. How do I prevent it's involvement. Why is it being involved when I
have not explicitly written to it? What am I missing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top