I have another issue:
I am able to build my VB.NET application. However, when I go to debug it, I get an unhandled exception:
System.InvalidOperationException occurred HResult=0x80131509
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object. Source=ProovePC StackTrace:
at ProovePC.My.MyProject.MyForms.Create__Instance__[T](T Instance) in :line 190 at ProovePC.My.MyProject.MyForms.get_Front1() at ProovePC.My.MyApplication.OnCreateMainForm() in C:\Users\Phillip\source\Workspaces\Upwork Projects\ProoveIt\ProovePC\My Project\Application.Designer.vb:line 35 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at ProovePC.My.MyApplication.Main(String[] Args) in :line 81Inner Exception 1: NullReferenceException: Object reference not set to an instance of an object.
The odd part is that it occurs in auto-generated code, in the Application.Designer.vb file. I have confirmed that the constructor is public and that the name of the form matches the name within this file:
Namespace My
'NOTE: This file is auto-generated; do not modify it directly. To make changes,
' or if you encounter build errors in this file, go to the Project Designer
' (go to Project Properties or double-click the My Project node in
' Solution Explorer), and make changes on the Application tab.
'
Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = true
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterAllFormsClose
End Sub
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.ProovePC.Front1 'Error occurs here?
End Sub
End Class
End Namespace
I am a little lost on this since I am new VB.NET, but I would like to think that the fix is a simple one. For those wondering, I am running visual studio 2017. I should note that I come from a C# background and recently got into vb.net. So please, explain as much as possible.
Edit:
Form Constructor:
Public Sub New()
' This call is required by the designer.
'NewMethod()
InitializeComponents()
' Add any initialization after the InitializeComponent() call.
End Sub
Edit:
Ok so here is the interesting part, now I am getting the error on the InitializeComponents function itself within the auto generated constructor of the form. Once I comment this function out, I am able to build and run the application. I only get so far because that application needs hardware to fully run which I have not connected yet.
Now, here is the interesting part, if I were to comment out the constructor, there is a line above it that comes back as undefined reference error:
Public MainStatus As StatusStrip = StatusStrip1 'Error is here now
'Public Sub New()
' This call is required by the designer.
'InitializeComponent()
' Add any initialization after the InitializeComponent() call.
'End Sub
For those wondering, I am now in the front1.vb file
there was a property within the form control that was being set to nothing when it needs to be set to Me.
As for the random line of code, Public MainStatus As StatusStrip = StatusStrip1
I think that it was accidentally copy pasted there as the variable is only used at that line. I commented it out and everything builds good now.
User contributions licensed under CC BY-SA 3.0