locked
System.AccessViolationException is being thrown by System.Windows.Forms.TreeView in VB.NET RRS feed

  • Question

  • Hi,

    Am getting below exception in a VB.NET Windows Application. Its crashing the VB.NET application  and closing it entirely.  This is happening in Window 10 Operating System. Can someone please help.

    System.AccessViolationException

      HResult=0x80004003

      Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

      

    Tuesday, July 30, 2019 7:52 PM

Answers

All replies

  • Hi,

    set in your VisualStudio:

    Tools->Options->Debugging->General

    uncheck option "Suppress JIT optimization on module load"

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f48c152-68cd-45ec-a11e-baa7de7f79c3/attempted-to-read-or-write-protected-memory?forum=csharpgeneral

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Farhan9 Thursday, August 8, 2019 2:18 PM
    Wednesday, July 31, 2019 8:42 AM
  • Hi Alex,

    Thanks for quick reply but unchecking the option "Suppress JIT optimization on module load"  didnt resolve the problem. I will be looking further on the link you have provided and let you know if that works.

    Thanks,

    Farhan

    Wednesday, July 31, 2019 3:14 PM
  • Below is the code snippet which is causing this issue. Marked the line in BOLD where the exception is being thrown. The application crashes and it never goes into Catch statement.

    Private Sub AddPassengerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddPassengerToolStripMenuItem.Click
            Try
                If ValidateForm() Then
                    Dim oPerson As New Passenger

                    CType(oPerson, PersonDetail).LoadDefaults(moOfficer.Id)
                    Dim oNode As TreeNode

                    If Not Me.TreeView1.SelectedNode Is Nothing Then
                        Dim oUnit As CrashUnit = Nothing
                        oUnit = GetUnit(Me.TreeView1.SelectedNode.Tag)

                        If Not oUnit Is Nothing Then
                            oPerson.UnitId = oUnit.Id
                            oNode = AddPersonNode(oPerson, Me.TreeView1.SelectedNode)
                        Else
                            oNode = AddPersonNode(oPerson)
                        End If
                    Else
                        oNode = AddPersonNode(oPerson)
                    End If

        Me.TreeView1.SelectedNode = oNode

                    oNode.EnsureVisible()

                    Me.cboPersonType.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Information, Me.Text)
                Try
                    Law.Common.SaveError(ex, "", "", "QuickCapture2.vb->AddPassengerToolStripMenuItem_Click")
                Catch ex2 As Exception
                End Try
            End Try
        End Sub

               
    Wednesday, July 31, 2019 3:51 PM
  • Hi,

    You can try  to add a namespace System.ComponentModel  ,

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 1, 2019 5:15 AM
  • This issue has been resolved. It was due to incorrect Selected Node in TreeView.
    Thursday, August 8, 2019 2:18 PM