Object reference not set to an instance of an object

moongodess

Active member
Joined
Dec 23, 2004
Messages
40
I have a project with many user controls.
What I need to do is insert some of them in a form.
For some reason I cant insert one of them :( It gaves me an error (attached)
What am I doing wrong??
 
This is happening in the designer when you drag it out from the toolbox?

It sounds like an error is occuring inside the control. Is it .Net? VB6 ActiveX? If it is something of your creation, you might want the controls source code for errors or debug it. If not, you might want to check and ensure compatability.
 
Yes marble_eater, this is happening when I drag it out from the toolbox :(
My project is a simple windows application (in vb.net) with some forms and user controls.
What I dont understand is why do I get an error with just one of the user controls. The others are ok.
All of them have the same properties, what changes is the controls in them..
 
Is the control one written in house or developed by a third party? Also is the control a .Net control or an ActiveX control you are using under .Net?

If it is a 3rd party control try re-installing it and see if that fixes the problem - if an inhouse control check there havent been any breaking changes made to it recently.
 
I think you can put MessageBox.Show into the constructor code of your control and they will be displayed when you create an instance in the designer. This will tell you where you are in your code and should help you narrow down where the error is coming from.
 
Looks like you have something in the control that isnt being created. What the code in the controls constructor or Load event look like?
 
IngisKahn said:
Repent from your old VB6 ways! Use Debug.WriteLine instead. :)
Besides the fact message boxes arent really the VB6 way (we did have Debug.Print in VB6, no?), MessageBox can be better; it pauses execution and you are certain to see the information, and you can break execution if the data doesnt seem right. Of course, it also requires removal or conditional compilation, and most of what you can do with a messagebox can also be done with breakpoints. Ultimately a matter of preference, I suppose.
 
Machaira said:
Looks like you have something in the control that isnt being created. What the code in the controls constructor or Load event look like?
:confused:
I have nothing in load event.. Ive created a LoadValues procedure to prevent that from happening.
That procedure is called only when the form (wich contain the control) displays.




jmcilhinney said:
I think you can put MessageBox.Show into the constructor code of your control and they will be displayed when you create an instance in the designer. This will tell you where you are in your code and should help you narrow down where the error is coming from.
I put messageboxes in new and initialize procedures, and I still couldnt see where the error is, because it is the first message I see.. No description, nothing..
 
marble_eater said:
Besides the fact message boxes arent really the VB6 way (we did have Debug.Print in VB6, no?), MessageBox can be better; it pauses execution and you are certain to see the information, and you can break execution if the data doesnt seem right. Of course, it also requires removal or conditional compilation, and most of what you can do with a messagebox can also be done with breakpoints. Ultimately a matter of preference, I suppose.

That makes sense. The point being: know what tools you have available. (Thou a break point is always > a message box IMO)

I made the VB6 comment because few are the MFC prorammers who debug using AfxMessageBox. :)
 
The fact of the matter is that we really dont know what is going on inside of your control and it is hard to give advice. The best one can do is tell you that you are trying to use an object you havent created. The control probably tries to access something that isnt created until LoadValues is called. Check youre Resize event handlers, Invalidate event handlers, etc. to see if they access an object that wouldnt be initialized at design time (since the LoadValues function probably wont get called at design time). Check any initialization code that will be called at design time. Throw in some message boxes, or debug output or something.
 
Back
Top