compiles as a form -- but not as a control

B

Bill Angus

I have a collection of controls that represent an address in my project. I wanted to make them into an address control because lots of the business objects I am working with have addresses.
I got a nice set of control that visually represent the data I need -- but when I aggregated the controls and code into a VB user-control, the designer gives me the pink screen of death and reports OBJECT REFERENCE NOT SET TO A VALID INSTANCE OF AN OBJECT,

Since the debugger will not parse code inside a user-control, I can't find the object which is giving me problems.
her is the message I get...

One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.

Object reference not set to an instance of an object.
Hide

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
 
C

Chris Dunaway

Have you tried removing the <System.Diagnostics.DebuggerStepThrough()>
attribute from the user control? That might allow you to step into the
control with the debugger.
 
M

Martin

Hi Bill,

So you created a class, and you instanced the class on a form at design
time. This class probably contains code with references to a database or an
other object that isn't available at design time.

What you need to do is to enclose those references in the following if
statement

If Not Me.DesignMode Then
.... reference MyObject
End If

The enclosed bits of code are executed at run-time but ignored in the
designer.

Hth,
Martin


I have a collection of controls that represent an address in my project. I
wanted to make them into an address control because lots of the business
objects I am working with have addresses.
I got a nice set of control that visually represent the data I need -- but
when I aggregated the controls and code into a VB user-control, the designer
gives me the pink screen of death and reports OBJECT REFERENCE NOT SET TO A
VALID INSTANCE OF AN OBJECT,

Since the debugger will not parse code inside a user-control, I can't find
the object which is giving me problems.
her is the message I get...

One or more errors encountered while loading the designer. The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes.

Object reference not set to an instance of an object.
Hide

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)
 
B

Bill Angus

Thanks Chris:

After reading your post, I found a line such as you describe in the designer generated code.... (which we are instructed not to edit). However, if I comment out this attribute, I still cannot step through the code of the user-control at run time. Can you tell me am I looking in the wrong place to try to get the debugger to allow me to debug code of a user-control as per your suggestion?
<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

Thanks all for your suggestions.

Bill Angus, MA
http://www.psychtest.com
Have you tried removing the <System.Diagnostics.DebuggerStepThrough()>
attribute from the user control? That might allow you to step into the
control with the debugger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top