DataTable在发布模式下是空的,但在调试模式下虽然我初始化了它

DataTable is empty in release mode, but not in debug mode although I initialized it

我的代码在调试模式下工作,但在发布模式下,我在第 6 行收到 MTable 的系统 NullReference 异常,我不知道原因。在调试模式下,我可以访问数据。

Dim myregex As Regex = New Regex("A[1-6]|A[A-M]") 
Dim MTable As New DataTable
Dim dvr As New System.Windows.Forms.DataGridViewRow

If datasetB.Tables.Contains("BLA") Then

    MTable = datasetB.Tables("BLA").Select().
Where(Function(r) myregex.IsMatch(r.Item("Data"))).ToArray().CopyToDataTable

    MTable.Columns.Add(New DataColumn("textt", GetType(String)))
    MTable.Columns.Add(New DataColumn("texttt", GetType(String)))
    MTable.Columns.Add(New DataColumn("textttt", GetType(String)))
    MTable.Columns.Add(New DataColumn("texttttt", GetType(String)))

    ErrorsDgV.DataSource = MTable

    For Each dvr In Me.ErrorsDgV.Rows

            If dvr.Cells(5).Value IsNot Nothing Then

                'do some things

            End If

        Next
    Else
        MsgBox("didn't work")
    End If

提前致谢!

我在Visual Studio中打开了Compiler Settings,在Configuration中选择了Release。然后我点击高级编译器设置。在那里我取消选中优化代码按钮。这样代码在调试模式下运行。