I am new to C# WinForms. I have made a class (EnhancedForm) which inherits Form class. In EnhanceForm I have put some common functions (like validations, common used objects like DataTable and string variables etc, so that I may not have to code same again and again in forms) that I want to use in all forms and next all of my forms inherits this (EnhancedForm).
In DAL (a separate class library) I have a class CommonDB class which have DB related common functions. For database communications I was making an object of CommonDB in all forms. I thought to put CommonDB in EnhancedForm so that I may not have to make its objects in all classes.
Here is something happening that I couldn’t understand. Application runs fine. But if I try to open a form in design view it gives an error. “Object reference not set to an instance of an object. “ I couldn’t view a form in designed mode. If I remove CommonDb object from EnhancedForm and put it in individual forms it works fine and allow to view forms.
If I compile and run this error do not appears. Please guide and help me in this regard.
Thanks
You have code in EnhancedForm that assumes a CommonDb object. At runtime you create that (probably in Form_Loaded) but Design-time it is absent.
Preferrably, all your code accessing CommonDb should check for null, and/or this.DesignMode