JohnM33

Hello all

I recently tracked down a problem in my code, where the designer would give me the White Screen of Death almost all the time when adding a particular control - although it would sometimes be ok after a Clean, it would always die again after a rebuild.

After a ridiculous amount of detective work, the likes of which I hope never to go through again, I tracked it down to one of the public properties of my user control calling a private function during it's "set" and, I assume because of the design time support for public properties of user controls, this was then being called during design and hitting a null reference. Of course this seems obvious now but I was following the MS advice to use properties rather than setXXX methods.

Does this make sense and, if so, is the the solution to this to use a method and not a public property That will certainly work - I don't think checks in the code itself to handle design time issues are a good idea. My question is, shouldn't the compiler highlight this with a warning or error, it wouldn't be hard Given the advice to use properties, shouldn;t this problem be made clear And couldn't such an error be made explicit rather than the completely opaque stack trace

Or am I missing something Any comments would be appreciated.

John



Re: Visual C# IDE Public properties and designer issues

Zamial

Hmm, are you using this property in the load method of a form or control perhaps

Or perhaps in a render or pre render or init method.

I'm sure these are fired when you open the designer and I to have suffered this painful issue Smile

It was possible to wrap around it with.

if(!DesignMode)

{

...

}

DesignMode returns true if you are not running the application and as such you can say if i'm not in design more (the app is running) execute this code. This will at least prevent your problem. If it is as I believe, in a load method somewhere.

Hope it helps. If not now then one day in teh future when it happens for this reason Smile





Re: Visual C# IDE Public properties and designer issues

JohnM33

No, the property was not used either in the constructor or in the OnLoad method.

Will certainly watch for this in future by guarding the code in some fashion as you say. My question is why this is not flagged by the designer, it is such an obvious error to point out - with a warning or something in the compiler maybe - that I'm doubting what I'm seeing with my own eyes and thinking either i'm doing something stupid or there is something going on that I'm missing that prevents any help from the IDE.





Re: Visual C# IDE Public properties and designer issues

Zamial

I know it's not flagged by the designer as the designer has to parse the code first and the exception is thrown whilst doing so.

I'm sorry it doesn't help solve your issue though.





Re: Visual C# IDE Public properties and designer issues

Chunsheng Tang - MSFT

Have you set BrowsableAttribute to false for that property






Re: Visual C# IDE Public properties and designer issues

JohnM33

No - haven't heard of that attribute before. Will try that later - thanks.