שתף באמצעות


Error only when opening a Form

Question

Sunday, July 1, 2018 5:13 PM

When I open the "Error List" there is no error, but when I open the Form it displays the following error:

2 ErrorsObject reference not set to an instance of an object. 
Instances of this error (1) 
1. Hide Call Stack

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkPropertyDescriptor.SetValue(Object component, Object value)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement) Top-level control cannot be added to a control. 

I do not understand what the above is trying to tell me.

All replies (8)

Monday, August 6, 2018 8:01 PM ✅Answered

it is fixed 

i double clicked the form and fixed the view and the errors get reed


Sunday, July 1, 2018 5:34 PM

 When you open the form how?  In the designer window or at run-time in your code?

If you say it can`t be done then i`ll try it


Monday, July 2, 2018 3:32 AM

Hi 

1.Did you mean that your code was incorrect when you run the code?
2.It is recommended that you use breakpoints to debug your code,
3."Object reference not set to an instance of an object" shows that you have not instantiated an object. An empty object will be used incorrectly. For example, string str=User.name; if User=null, report this error.

Best Regards,

Alex

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


Monday, July 2, 2018 1:02 PM

You may have a custom control that was added to a form in the designer and then you made some significant change to that control without first removing the existing instance from the form.

If this is the case (or something similar) you will need to use the Show All Files button on the solution explorer, open the .designer code file for the form, and delete all references to the custom control instance.

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


Thursday, July 5, 2018 6:51 PM

When I open the "Error List" there is no error, but when I open the Form it displays the following error:
when I open "view code" on the form, and "View code" on the Designer of the form, there are no errors, warnings, messages etc.

But when I right click on the form and I select "Open" or I select "view Designer" it shows me the above error messages.

Thanks in Advence


Thursday, July 5, 2018 7:01 PM

When I open the "Error List" there is no error, but when I open the Form it displays the following error:

2

 ErrorsObject reference not set to an instance of an object. Instances of this error (1) 1. Hide Call Stackat System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkPropertyDescriptor.SetValue(Object component, Object value)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializePropertyAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement, CodePropertyReferenceExpression propertyReferenceEx, Boolean reportError)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement) Top-level control cannot be added to a control. 

when I open "view code" on the form, and "View code" on the Designer of the form, there are no errors, warnings, messages etc.

But when I right click on the form and I select "Open" or I select "view Designer" it shows me the above error messages.

Thanks in Advence

Hi

I can't reproduce any of those issues. You say you can view the code,would you post the code here (use the code tool from the toolbar for code)

*

Another thing to try: start a new project and add some controls in the Designer, double click on each of those controls which will create default handler blocks for them. Youdon't need to add any other code at this stage, just try and switch between Designed and Code editor to see if that all works correctly.

Regards Les, Livingston, Scotland


Thursday, July 5, 2018 9:21 PM

 As Reed suggested to you,  this is often an error that is caused by a custom control class or sometimes even a UserControl that has been added to the Form.  What kind of controls did you have added to this form?  Do you have a custom control class that you added to your project?

 If you had one or more of these controls on the form and you changed the code in the control class,  that can cause the error.  You will have to open the "YourFormName.Designer.vb" file and remove all references to the custom control(s).  Then you will have to Rebuild the project and add new instances of them to the Form.

 

If you say it can`t be done then i`ll try it


Friday, July 6, 2018 11:47 AM

If I had to guess (which I do) I would say the OP started with a class that inherited from Control or UserControl and then later (after putting an instance on the Form) decided to change the class to inherit from Form for whatever reason.

That guess is based on this part of the error message:

"Top-level control cannot be added to a control."

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"