Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Control problem

Status
Not open for further replies.

9727604

Programmer
Jul 18, 2003
23
0
0
CA
Dear all,
I have created a custom control in C# (A panel with context menu's, event handlers etc already built in) in a dll, a control library. I've added this control to my user controls in my main application (a different project). I can then drag the panel onto my main form and resize it etc. The main form builds fine but when i run it and click on a panel I get an error "Object reference not set to an instance of an object". It is like the inputpanel object is not getting initialised properly. I create the object in the mainform and call the constructor to initialise it (along with InitializeComponent()). Does anyone have any idea what i'm doing wrong. Thanks in advance
 
If you aren't already - add the control library project to your main application's solution. Right click on the solution and say "Add Existing Project"

Then right click on your main project's references and say "Add Reference" navigate to the "Projects" tab and include your control library project as a reference.

This will let you debug it as it loads. Breakpoint your constructor and step through it. That should give you a good idea what's going on.

As an added note: sometimes VS.net erases some code for no apparent reason. In InitializeComponent() you may be missing the line

yourusercontro1 = new namespace.project.yourusercontrol;

Then when you try to assign properties to it later, it would throw the null reference exception.
 
Yeah i've already added the Dll to the main application and referenced it. The main application builds fine so it can definitely 'see' the control in the dll. I tried putting a break point in the main application at the point where the control is instantiated i.e.
this.inputPanel = new ControlLibrary.InputPanel();
However the debugger will not let me step into this constructor, it creates the object alright and when i look at it using quickwatch i can see all the properties set. Once the main form is running however and i click on this panel I get the error. I've tried putting a break point at the first line in the event method but this method isn't even entered. I'm completely lost and can't find anything online
 
It sounds like you don't have the project included in your solution - just the DLL.

If you don't actually add the project you can't step into it. The project is obviously where the error is being thrown. Include the project, not the dll!
 
The project was included aswell, sorry for not making that clear. I have a library project and exe project in the same solution with the exe set as startup project. I don't understand how I cannot step into the library code. For some reason the object in the dll isn't getting initialised properly
 
You might want to create a test form in your control library. You'll have to change it to a windows form for a few minutes but at least your checks could be local that way.

If you want - post your usercontrol code here and i'll look at it - or email it to me


llamachant at yahoo dot ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top