首页 > 解决方案 > System.InvalidOperationException: '创建表单时出错

问题描述

在尝试运行/调试 WindowsForm 的代码时,我遇到了以下异常:

System.InvalidOperationException HResult=0x80131509 消息=创建表单时出错。有关详细信息,请参阅 Exception.InnerException。错误是:对象引用未设置为对象的实例。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()在 C:\Users\M0110823\source\repos\Automated SoundPower Testing\My Project\Application.Designer.vb:第 35 行 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel( ) 在 Microsoft.VisualBasic。

内部异常 1:NullReferenceException:对象引用未设置为对象的实例。”

此异常参考:

Me.MainForm = Global.Automated_SoundPower_Testing.Form1

我认为这可能是因为我试图在创建之前调用 Me.Mainform ?还是目录和项目属性之间可能存在命名错误?我创建了空白项目并传输了代码/vb 表单并遇到了同样的错误。这让我相信我的代码中有一些错误?

这是我的代码的第一部分,之后的所有内容都被分类到 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)

运行时异常

标签: vb.netvisual-studio

解决方案


推荐阅读