Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Windows Forms Component Initialization NullReferenceException

I described the Observer Pattern recently and how events fire out to observers of a Subject and how actions across panels and lists are wired through the Subject.  This Subject class is a Component class.  The Container is passed as a reference on Component Initialization.  I occasionally get the error below, which is fixed by adding the line below to invoke the mainform's container constructor.  This keeps getting deleted by the Designer generated Initialization Code.  Don't know if its a beta 2.0 thing or something I'm mishandling.

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
// etc...

 

Comments (2) | Post RSS RSS comment feed

Posted on 6/27/2005 6:04:00 PM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (2) -

6/30/2005 12:43:31 PM Permalink

Have you tried putting the custom constructor in the partial class that you can modify instead of directly in MyForm.Designer.cs?

Maybe the IDE says "this is MY file, mess with it and you're dead meat."

You also may want to new this.components where it's declared (if you know you want to use it) this will by default slap the initialization in the static ctor that gets executed before event the default parameterless ctor.

-Christopher
ASP.NET MVP | AspInsider
http://www.chrisfrazier.net/blog

Chris Frazier |

6/30/2005 2:11:34 PM Permalink

Chris, Thanks so much for your input and explanations.  I'll definitely use one or both of your suggestions next time I hit the error.

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke