An error occurred while creating the form. See Exception.InnerException for more details. Error: The reference to the object is not installed in the instance of the object

I get this error when trying to debug my form, I don’t see where the error may be at all (also does not highlight where), who has suggestions?

An error occurred while creating the form. See Exception.InnerException for details. Error: Object link not set to instance object.

Dim dateCrap As String = "Date:" Dim IPcrap As String = "Ip:" Dim pcCrap As String = "Computer:" Dim programCrap As String = "Program:" Dim textz As String Dim sep() As String = {vbNewLine & vbNewLine} Dim sections() As String = Text.Split(sep, StringSplitOptions.None) Dim NewArray() As String = TextBox1.Text.Split(vbNewLine) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load textz = TextBox1.Text End Sub 
+4
source share
3 answers

The error is here:

 Dim textz As String = TextBox1.Text 

and here:

 Dim NewArray() As String = TextBox1.Text.Split(vbNewLine) 

and maybe here:

 Dim sections() As String = Text.Split(sep, StringSplitOptions.None) 

You cannot initialize such an element, because this code is mainly executed in the constructor, until TextBox1 (or any other control / property) is initialized, therefore, it is Nothing .

Put all the initializations related to the controls inside the Form_Load event - that’s what it is for him.

+3
source

Disable "Only my code" in the "Debugging" section of the "Settings> General" tab. This will show you where the exact error came from.

+2
source

I had the same symptoms - debugging did not even start, since the error appeared before any of my codes started working. Eventually tracked it down to the resize event handler:

Private Sub frmMain_Resize (sender as object, e As System.EventArgs) processes Me.Resize

 ArrangeForm() 

End Sub

As soon as I deleted the handler, the error disappeared. The strange thing is that it worked for about 3 weeks (while I was developing other parts of the code) without any problems and just spontaneously stopped working. The ResizeEnd event handler did not cause problems.

Just post it if someone else is unsuccessful enough to encounter the same issue. It took me 8 hours to track it.

0
source

Source: https://habr.com/ru/post/1310252/


All Articles