473,468 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Object Reference when adding UserControl

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.
Nov 21 '05 #1
2 1205
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

"Shallotx" wrote:
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.

Nov 21 '05 #2
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

"Charlie" wrote:
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

"Shallotx" wrote:
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.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
9
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
3
by: j-in-uk | last post by:
I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx. Continents is a usercontrol placed in Albums. In Album.aspx.cs I need to access a property from the Continents usercontrol and is...
0
by: j-in-uk | last post by:
I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx. Continents is a usercontrol placed in Albums. In Album.aspx.cs I need to access a property from the Continents usercontrol and is...
1
by: j-in-uk | last post by:
I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx. Continents is a usercontrol placed in Albums. In Album.aspx.cs I need to access a property from the Continents usercontrol and is...
1
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.