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 ?
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 ?