views:

507

answers:

2

I intermittently get this in error in my .NET 1.1 C# Windows Forms application. Someone indicated that this is due to a bug in the 1.1 framework and suggests putting the following code into any custom controls.

protected override void OnParentChanged(EventArgs e)
{
  if (this.Parent != null)
  {
    this.CreateParams.Parent = this.Parent.Handle;
    this.RecreateHandle();
  }
  base.OnParentChanged(e);
}

Has anyone else found that this solved the problem for them? Can anyone provide a way to consistently reproduce the error, so I can verify it is fixed after I apply the changes?

If there is an alternative solution I'm open to that as well.

A: 

Hey, I'm not sure about your problem as I haven't used .NET 1.1 in ages, and I hate to state the obvious... but what is stopping you from migrating to .NET 2.0 or even 3.5? (Please do not feel offended, I'm actually interested in knowing).

I can understand .NET 3.5 might be early in some cases, but .NET 2.0 should be a safe bet given the fact that most users have it either through windows updates or if they are using Vista they have it by default.

TimothyP
I would have liked some feedback though .....
TimothyP
+1  A: 

From the title it seems that your code is trying to access an already disposed object. This can happen in finalizer if you try to access a managed reference field. The order CLR finalizes managed objects is non-deterministic.

Petar Repac