# [.net] 4-line guaranteed .NET crash - what am I doing wrong?

## Recommended Posts

Geronimo2000    270
My program has a more sophisticated structure, but I narrowed the problem down to this, and you don't usually need to use 40 as the initial count. The problem appears to be specific to the PropertyGrid control. Other controls do not have this problem. I'm assuming I am supposed to do something, but am not - could you please point out what I ought to be doing? The exception I get on my machine is System.Runtime.InteropServices.ExternalException... GDI+ is not properly initialized. I hope most of you get the same exception...

static void Main()
{
int x = 40;
while(x-- > 0)
{
PropertyGrid g	= new PropertyGrid();
Form f		= new Form();
f.Controls.Remove(g);
}
}



##### Share on other sites
darookie    1441
Apart from the rather obscure sample, I don't get any exception at all.
What OS are you using and which version of the .NET framework?
(I tested on Win2k .NET v1.1, all updates up to 2.0 beta installed)

##### Share on other sites
Geronimo2000    270
Sometimes it will work the first time I try it on a different machine or the first few times, but then it will consistently fail from then on.

The only machines I have tested this on are XP (Service Pack 2) with the latest .NET 1.1 update. I'm not familiar wtih the 2.0 beta - I guess I need to try that out once I find it.