design mode null object reference error

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

I inherited a nightmare WinForms app ...

One problem I'm having is design-time null object reference problems.

This particular problem is related to a form "Form1", instances of which
are instantiated and displayed on other forms. Form1 has a property ( get
set ) "Property1" that is somehow getting referenced design-time and
throwing the error

"Code generation for property "Property1" failed. Error was: 'Property
accessor 'Property1 on object 'form1' threw the following exception: 'Object
reference not set to an instance of an object."

I searched the entire code base for "form1.Property1" and I find it in two
places. I wrap those two references in code that detects if currently in
design-time mode :

if ( !IsDesigner() )
{
// do whatever with form1.Property1
}

The IsDesigner() method is as follows :

public static bool IsDesigner()
{
bool result = false;

try
{
result =
Process.GetCurrentProcess().ProcessName.ToLower().StartsWith( "devenv" );
}
catch { }

return result;
}



This is not solving my problem.

Any ideas anyone ?
 
I did reply to this.. Are my posts not being seen? I can't see my replies.
Odd..

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
I did reply to this.. Are my posts not being seen? I can't see my replies.
Odd..

In this thread I see only this message, so I also don't see your
original reply.
 
Back
Top