0

Upon trying to run/debug code of a WindowsForm I run into the following exception:

System.InvalidOperationException 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=Automated SoundPower Testing StackTrace: at Automated_SoundPower_Testing.My.MyProject.MyForms.Create__Instance__[T](T Instance) in :line 190 at Automated_SoundPower_Testing.My.MyProject.MyForms.get_Form1() at Automated_SoundPower_Testing.My.MyApplication.OnCreateMainForm() in C:\Users\M0110823\source\repos\Automated SoundPower Testing\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 Automated_SoundPower_Testing.My.MyApplication.Main(String[] Args) in :line 81

Inner Exception 1: NullReferenceException: Object reference not set to an instance of an object."

This exception references:

Me.MainForm = Global.Automated_SoundPower_Testing.Form1

I'm thinking this could possibly be due to the fact that I am trying to call Me.Mainform before it has been created? Or is there possibly a naming miscommunication between the directory and the project properties? I have created blank project and transferred code/vb form over and run into the same error. This leads me to believe that there is some error in my code?

This is the first section of my code, everything after this is categorized into regions under Class Form1.

Imports System.Windows.Forms
Imports System.Windows.Controls.Label
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Imports Microsoft.Office.Interop
Imports LMSTestLabAutomation
Imports System.IO.File
Imports System.IO.Path
Imports System.Threading
Imports System.ComponentModel
Imports System.Runtime.InteropServices

Class Form1
    Dim TL As LMSTestLabAutomation.Application
    Public tlDb As IDatabase
    Dim SaveDataName As String
    'Declare UA variables
    Dim UAmodel, UAtype, UAsn, UAoperator, UAdate, UAcomment,
        UAtesttype, UAtestpurpose, UAtime, UAtestduration As String
    Dim UAlist As New SortedList(Of String, String)
    Dim AcqState As String = "Acquisition Offline"
    Dim aRecordTime As Boolean() = New Boolean() {}
    Dim aRunNames As String() = New String() {}
    Dim aProjectNames As String() = New String() {}
    Dim aStatus As String() = New String() {}
    Dim aStartTrigger As Single() = New Single() {}
    Dim aStopTrigger As Single() = New Single() {}
    Dim aTriggerCondition As String() = New String() {}
    Dim aSequences As Integer() = New Integer() {}
    Dim newTestIncrement As Integer
    Dim newTest As String() = aRunNames
    'Declarations of the used objects
    Dim database As LMSTestLabAutomation.IDatabase
    Dim datawatch_pictManag As LMSTestLabAutomation.IDataWatch
    Dim WithEvents gDataWatch_AcqState As LMSTestLabAutomation.DataWatch
    Dim pictManag As LMSTestLabAutomation.IPictureManager
    Dim myPicture As LMSTestLabAutomation.IPicture
    Dim myBlock As LMSTestLabAutomation.IBlock2
    Dim myDisplay As LMSTestLabAutomation.IDisplay
    Dim Measure_Port As LMSTestLabAutomation.DataWatch
    Dim Open_book = TL.ActiveBook
    Dim sequence_number = Open_book(0, 2)

runtime exception

Luke
  • 5
  • 2
  • Do you have a `Form1` or maybe you renamed the class? – Jimi Oct 22 '19 at 21:00
  • The line which raises the exception is boiler-plate Visual Studio auto-generated code. You probably shouldn't be modifying anything in that file (are you?). Please post some code (not in an image this time, edit your question, adding actual code) so we can further help you. – djv Oct 22 '19 at 21:23
  • And I disagree with the duplicate marking. OP has some standard winforms code which is raising the exception - I personally don't know how I would make that line raise an exception if I wanted to, so there may be something more complicated going on, which deserves more attention than closure. Luke, please provide the information I asked for above, I'd like to help if I can. – djv Oct 22 '19 at 21:32
  • As the message shown in your image states "An error occurred creating the form". In this case, the form in Form1. The error is occurring in the `Sub New()`. If you did not explicitly code a `Sub New`, look at class level variable declarations/initializers as the initialization part will be written by the compiler into a generated `Sub New`. i.e. `Dim something as SomeObject = New SomeObject`. – TnTinMn Oct 22 '19 at 23:29

0 Answers0