Object Reference when adding UserControl

G

Guest

I am building a simple user control - a listview, a couple buttons. I build
the solution, drop the control on a form, and all is well. I then go back,
modify the Usercontrol, rebuild, and still all is well. However, at some
point I get the "Object Refererence not
set to an instance..." error when I rebuild. If I try to drop the control
on another form I get the same error. I do not believe it is the code in the
usercontrol, as it works fine as a "Form" rather than a "Control".
Additionally, I have removed all the code from the Usercontrol except Public
Class SearchCriteria Inherits System.Windows.Forms.UserControl and the
Windows Form Designer generated code and I still get the same error.

Any help/suggestions would be appreciated.
 
G

Guest

Make sure you don't have multiple references to different versions of the
control.
Look in "Customize Toolbox" to see if there could be another control with
the same name, or a different version of the same control. Could there be a
debug version of the dll running in addition to the exe version, and you are
not pointing to the correct one?

Once you know you are pointing to the intended control, use try blocks
around all your code in the user control and output the stacktrace property
of the exception instance in a message box. The last line shows the number
the line of offending code. This can be useful for design time errors,
because some of your code runs when you attempt to instantiate a user control.

www.charlesfarriersoftware.com
 
G

Guest

Thank you so much!! The stacktrace property was exactly what was needed to
find the offending code. I do not know how I would survive without guys like
you helping guys like me.

Tom
 

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