Page 1 of 2 12 LastLast
Results 1 to 40 of 45

Thread: [RESOLVED] Fixing program crashes that do not throw an exception

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Resolved [RESOLVED] Fixing program crashes that do not throw an exception

    The program I developed for my workplace's helpdesk, I built in a ping tool which emulates the way ping.exe but using .NET ping class. Works great.

    However from time to time the program will crash on continous pings. It's totally random and I need to know why, because it throws a memory dump and crash. I have the files.

    How do I deal with this? Because I tried to cause it to crash in visual studio and it just doesn't... doesn't throw any exception with numerous pings going at the same time.. but with the compiled exe... sometimes..... just does...

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,761

    Re: Fixing program crashes that do not throw an exception

    One thing you should do is wrap the process that crashes into a Try/Catch statement. Then use My.Application.Log.WriteException to document the exception. After an exception gets thrown, ask the user to fill out a form asking what he/she was attempting to do and when did it occur. Then get exception details and follow up from there.

    Without the exception, there's not much you can do.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    It just crashed on me, I clicked debug and this is what I get:

    An unhandled exception of type 'System.NullReferenceException' occurred in Helpdesk Toolkit.exe

    Additional information: Object reference not set to an instance of an object.

    It's happening during the ping when the window runs and the ping thread runs, it updates the richtextbox in the new window.

    Totally random as it could be 100 hops, or it could be 10 hops, in this case when it just crashed on me happened on 3 hops.

    The thing is it is random could happen anytime but pretty rare but when it happens it happens... I had the program open 6 hours and no issues.. and now...



    Edit: The thing is it's not giving me the code obviously because its the exe i was debugging...
    Last edited by a_ahmed; Oct 17th, 2014 at 12:18 PM.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Fixing program crashes that do not throw an exception

    Its likely that you are throwing an exception on a thread, which would need to be caught using an UnhandledException handler.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    But normally I get the window thrown with continue/exit. This one just crashes straight up.

    I know which process it is, but im not sure how to catch where this is happening... i mean i know how to do a try catch, etc... but it only happens with the program being compiled..

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,761

    Re: Fixing program crashes that do not throw an exception

    A NullReferenceException occurs whenever you try to use an object in anyway, but the object is Nothing. Here is an example of where a NullReferenceException would occur:
    Code:
    Dim foo As List(Of String)
    foo.Add("Foo")
    To correct the error, I'd need to set the object to a new instance:
    Code:
    Dim foo As List(Of String) = New List(Of String)
    foo.Add("Foo")
    So my question to you is where in your process are you either declaring an object or trying to use an object? That is most likely where your exception is occurring.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    It would be nice if you could track this down to a single line, but since the exception is a NullReferenceException, you might be able to find it just by studying the code. After all, if any branch of the code is able to reach an object before you have created it, that's likely to be your problem.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    vb Code:
    1. Imports System.Net.NetworkInformation
    2. Imports System.Net
    3. Imports System.Threading
    4. Imports System.Text
    5. Imports System.Net.NetworkInformation.IcmpV4Statistics
    6. Public Class PingWindow
    7.     Public Closeme = False
    8.     Public Completion = False
    9.     Public Unreachable = False
    10.     Public ClipBoarderC = False
    11.     Delegate Sub SetTextCallback(ByVal text As String)
    12.     Private Sub PingWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    13.         Me.Icon = My.Resources.PingIcon
    14.         'SetWindowText(Me.Handle.ToInt32, "Pinging")
    15.     End Sub
    16.     Public Sub sbU(ByVal text As String)
    17.         If ConsoleTxtBox.InvokeRequired Then
    18.             Dim d As New SetTextCallback(AddressOf sbU)
    19.             Try
    20.                 Me.Invoke(d, New Object() {text})
    21.             Catch ex As System.ObjectDisposedException
    22.             End Try
    23.         Else
    24.             ConsoleTxtBox.Text += text
    25.             Try
    26.                 ConsoleTxtBox.SelectionStart = ConsoleTxtBox.Text.Length
    27.                 ConsoleTxtBox.ScrollToCaret()
    28.             Catch ex As System.ObjectDisposedException
    29.             End Try
    30.         End If
    31.     End Sub
    32.     Private Sub EK3Email_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown, WindowTitleLabel.MouseDown, ConsoleTxtBox.MouseDown
    33.         drag = True 'Sets the variable drag to true.
    34.         mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
    35.         mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable mousey
    36.     End Sub
    37.     Private Sub EK3Email_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove, WindowTitleLabel.MouseMove, ConsoleTxtBox.MouseMove
    38.         'If drag is set to true then move the form accordingly.
    39.         If drag Then
    40.             Me.Top = Windows.Forms.Cursor.Position.Y - mousey
    41.             Me.Left = Windows.Forms.Cursor.Position.X - mousex
    42.         End If
    43.     End Sub
    44.     Private Sub EK3Email_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp, WindowTitleLabel.MouseUp, ConsoleTxtBox.MouseUp
    45.         drag = False 'Sets drag to false, so the form does not move according to the code in MouseMove
    46.     End Sub
    47.  
    48.     Sub Pinger(ByVal Address As String, ByVal WindowTitle As String)
    49.         WindowTitleLabel.Text = "[ " & WindowTitle & " ]"
    50.         SetWindowText(Me.Handle.ToInt32, WindowTitle)
    51.         Closeme = False
    52.         Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    53.         Dim buffer() As Byte = Encoding.ASCII.GetBytes(data)
    54.         Dim timeout As Integer = 1000
    55.         Dim ip As IPAddress = Nothing
    56.         Dim ping As New System.Net.NetworkInformation.Ping
    57.         Dim options As New System.Net.NetworkInformation.PingOptions
    58.         options.Ttl = 128
    59.         options.DontFragment = True
    60.         If CheckForAlphaCharacters(Address) Then
    61.             Try
    62.                 ip = Dns.GetHostEntry(Address).AddressList(0)
    63.                 sbU("Pinging " & Address & " [" & ip.ToString & "] with " & buffer.Length & " bytes of data:" & vbNewLine)
    64.             Catch ex As System.Net.Sockets.SocketException
    65.                 sbU("Ping request could not find host " & Address & ". Please check the name and try again.")
    66.                 Completion = True
    67.                 Unreachable = True
    68.                 Exit Sub
    69.             End Try
    70.         Else
    71.             sbU("Pinging " & Address & " with " & buffer.Length & " bytes of data:" & vbNewLine)
    72.         End If
    73.  
    74.         Dim PacketsSent = 0
    75.         Dim PacketReceived = 0
    76.         Dim PacketLost = 0
    77.         Dim MinimumMS = 9999
    78.         Dim MaximumMS = -1
    79.         Dim TotalMS
    80.         Dim Execute As New Thread(Sub()
    81.                                       Do While Closeme = False
    82.                                           Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
    83.                                           Try
    84.                                               Select Case ping.Send(Address).Status
    85.                                                   Case Net.NetworkInformation.IPStatus.Success
    86.                                                       sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, reply.Address.ToString, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl))
    87.                                                       PacketReceived += 1
    88.                                                       Thread.Sleep(1000)
    89.                                                       'Case Net.NetworkInformation.IPStatus.packettoosmall
    90.                                                       '    sbU("Reply buffer too small." & vbNewLine)
    91.                                                       '    Thread.Sleep(1000)
    92.                                                   Case Net.NetworkInformation.IPStatus.DestinationNetworkUnreachable
    93.                                                       sbU("Destination net unreachable." & vbNewLine)
    94.                                                       Thread.Sleep(1000)
    95.                                                   Case Net.NetworkInformation.IPStatus.DestinationHostUnreachable
    96.                                                       sbU("Destination host unreachable." & vbNewLine)
    97.                                                       Thread.Sleep(1000)
    98.                                                   Case Net.NetworkInformation.IPStatus.DestinationProtocolUnreachable
    99.                                                       sbU("Destination protocol unreachable." & vbNewLine)
    100.                                                       Thread.Sleep(1000)
    101.                                                   Case Net.NetworkInformation.IPStatus.DestinationPortUnreachable
    102.                                                       sbU("Destination port unreachable." & vbNewLine)
    103.                                                       Thread.Sleep(1000)
    104.                                                   Case Net.NetworkInformation.IPStatus.NoResources
    105.                                                       sbU("No resources." & vbNewLine)
    106.                                                       Thread.Sleep(1000)
    107.                                                   Case Net.NetworkInformation.IPStatus.BadOption
    108.                                                       sbU("Bad option." & vbNewLine)
    109.                                                       Thread.Sleep(1000)
    110.                                                   Case Net.NetworkInformation.IPStatus.HardwareError
    111.                                                       sbU("Hardware error." & vbNewLine)
    112.                                                       Thread.Sleep(1000)
    113.                                                   Case Net.NetworkInformation.IPStatus.PacketTooBig
    114.                                                       sbU("Packet too big." & vbNewLine)
    115.                                                       Thread.Sleep(1000)
    116.                                                   Case Net.NetworkInformation.IPStatus.TimedOut
    117.                                                       sbU("Request timed out." & vbNewLine)
    118.                                                   Case Net.NetworkInformation.IPStatus.BadHeader
    119.                                                       sbU("Bad request" & vbNewLine)
    120.                                                       Thread.Sleep(1000)
    121.                                                   Case Net.NetworkInformation.IPStatus.BadRoute
    122.                                                       sbU("Bad route" & vbNewLine)
    123.                                                       Thread.Sleep(1000)
    124.                                                   Case Net.NetworkInformation.IPStatus.TtlExpired
    125.                                                       sbU("Reply from " & reply.Address.ToString & " The time to live (TTL) expired in transit." & vbNewLine)
    126.                                                       PacketReceived += 1
    127.                                                       Thread.Sleep(1000)
    128.                                                   Case Net.NetworkInformation.IPStatus.TtlReassemblyTimeExceeded
    129.                                                       sbU("The time to live expired during fragment reassembly." & vbNewLine)
    130.                                                       Thread.Sleep(1000)
    131.                                                   Case Net.NetworkInformation.IPStatus.ParameterProblem
    132.                                                       sbU("Parameter problem" & vbNewLine)
    133.                                                       Thread.Sleep(1000)
    134.                                                   Case Net.NetworkInformation.IPStatus.SourceQuench
    135.                                                       sbU("Source quench - Datagrams are arriving too fast to be processed and datagrams may have been discarded." & vbNewLine)
    136.                                                       Thread.Sleep(1000)
    137.                                                       'Case Net.NetworkInformation.IPStatus.OptionTooBig
    138.                                                       '    sbU("Option too big." & vbNewLine)
    139.                                                       '    Thread.Sleep(1000)
    140.                                                   Case Net.NetworkInformation.IPStatus.BadDestination
    141.                                                       sbU("Bad destination." & vbNewLine)
    142.                                                       Thread.Sleep(1000)
    143.                                                       'Case Net.NetworkInformation.IPStatus.NegotiatingIPSEC
    144.                                                       '    sbU("Negotiating IPSEC." & vbNewLine)
    145.                                                       '    Thread.Sleep(1000)
    146.                                                   Case Net.NetworkInformation.IPStatus.Unknown
    147.                                                       sbU("A general failure. This error can be returned for some malformed ICMP packets." & vbNewLine)
    148.                                                       Thread.Sleep(1000)
    149.                                               End Select
    150.                                               If reply.RoundtripTime < MinimumMS Then MinimumMS = reply.RoundtripTime
    151.                                               If reply.RoundtripTime > MaximumMS Then MaximumMS = reply.RoundtripTime
    152.                                               TotalMS += reply.RoundtripTime
    153.                                               PacketsSent += 1
    154.                                               If Closeme = True Then
    155.                                                   PacketLost = PacketsSent - PacketReceived
    156.                                                   sbU(vbNewLine & String.Format("Ping statistics for {0}:" & vbNewLine & vbTab & _
    157. "Packets: Sent = {1} Received = {2} Lost = {3} ({4}% loss)" & vbNewLine, Address, PacketsSent, PacketReceived, PacketLost, (PacketLost / PacketsSent * 100)))
    158.                                                   sbU(vbNewLine & String.Format("Approximate round trip times in milli-seconds:" & vbNewLine & vbTab & _
    159. "Minimum = {0}ms, Maximum = {1}ms, Average = {2}ms" & vbNewLine, MinimumMS, MaximumMS, Math.Ceiling(TotalMS / PacketsSent)))
    160.                                                   Completion = True
    161.                                               End If
    162.                                           Catch ex As System.Net.NetworkInformation.PingException
    163.                                               MsgBox(ex.InnerException.Message)
    164.                                           End Try
    165.                                       Loop
    166.  
    167.                                   End Sub)
    168.         Execute.Start()
    169.     End Sub
    170.     Sub clipboarder()
    171.         If Me.InvokeRequired Then
    172.             Me.Invoke(New MethodInvoker(AddressOf clipboarder))
    173.         Else
    174.             Clipboard.SetText(ConsoleTxtBox.Text, TextDataFormat.Text)
    175.             ClipBoarderC = True
    176.         End If
    177.     End Sub
    178.     Function CheckForAlphaCharacters(ByVal StringToCheck As String)
    179.         For i = 0 To StringToCheck.Length - 1
    180.             If Char.IsLetter(StringToCheck.Chars(i)) Then
    181.                 Return True
    182.             End If
    183.         Next
    184.         Return False
    185.     End Function
    186.     Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
    187.         Closeme = True
    188.         If Unreachable = True Then
    189.             Do While Completion = False
    190.             Loop
    191.             Me.Close()
    192.         Else
    193.  
    194.  
    195.             Dim res As MsgBoxResult = MessageBox.Show("Do you want to copy results to clipboard?", AppTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
    196.             If res = MsgBoxResult.Yes Then
    197.                 Dim Execute As New Thread(Sub()
    198.                                               Do While Completion = False
    199.                                               Loop
    200.                                               clipboarder()
    201.                                               Me.Close()
    202.                                           End Sub)
    203.                 Execute.Start()
    204.             Else
    205.                 Me.Close()
    206.             End If
    207.         End If
    208.     End Sub
    209.  
    210.     Private Sub btnMinimize_Click(sender As Object, e As EventArgs) Handles btnMinimize.Click
    211.         Me.WindowState = FormWindowState.Minimized
    212.     End Sub
    213. End Class

    Here's the code, it's pretty cool on it's own I was going to refine it and post it up in the code bank.

    Basically the window emulates the ping.exe console window, but it's actually ping class and a richtextbox with a label which gets updated.

    When calling the window:

    You would go Pinger(ipaddress, windowtitle)

    the windowtitle is actually the label. I get that information from the main windnow (what type of device, more details about the IP, etc...)

    Pressing the close button generates the results and prompts a yes/no copy to clipboard.

    Once copied to results the window closes. It has a few if checks.

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,761

    Re: Fixing program crashes that do not throw an exception

    You have a Try/Catch statement, but you do nothing with the exception. That should be the first red flag. While I haven't had the chance to fully read the code, I believe the exception is being thrown on this line here:
    Code:
    ip = Dns.GetHostEntry(Address).AddressList(0)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    It can't be this line because this runs once on start and that's it. It's the opening statement in the window. I also already had a catch statement for the error that I knew was being thrown if invalid socket exception:

    vb Code:
    1. If CheckForAlphaCharacters(Address) Then
    2.             Try
    3.                 ip = Dns.GetHostEntry(Address).AddressList(0)
    4.                 sbU("Pinging " & Address & " [" & ip.ToString & "] with " & buffer.Length & " bytes of data:" & vbNewLine)
    5.             Catch ex As System.Net.Sockets.SocketException
    6.                 sbU("Ping request could not find host " & Address & ". Please check the name and try again.")
    7.                 Completion = True
    8.                 Unreachable = True
    9.                 Exit Sub
    10.             End Try
    11.         Else
    12.             sbU("Pinging " & Address & " with " & buffer.Length & " bytes of data:" & vbNewLine)
    13.         End If]

    The crash happens while the ping is happening, so it would be after this piece of code,

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    The formatting on the site messed that code up pretty badly, but I did notice this:

    Catch ex As System.Net.NetworkInformation.PingException

    You are catching one particular type of exception there, but that wouldn't catch a NullReferenceException. So, if anything in that Try block threw the exception you are seeing, it wouldn't get caught, and there is something in there that 'might' throw such an exception. It isn't clear to me if ping.Send can EVER return Nothing, but it does seem possible, in which case Reply would be Nothing, which would then cause trouble when you tried to access it. Better yet, that exception would be thrown on a different thread, so it may fit pretty well.
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    The opening line is like the opening line of ping.exe

    This whole small form is emulating basically hwo ping.exe behaves and displays the information and at the end the results


  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Quote Originally Posted by Shaggy Hiker View Post
    The formatting on the site messed that code up pretty badly, but I did notice this:

    Catch ex As System.Net.NetworkInformation.PingException

    You are catching one particular type of exception there, but that wouldn't catch a NullReferenceException. So, if anything in that Try block threw the exception you are seeing, it wouldn't get caught, and there is something in there that 'might' throw such an exception. It isn't clear to me if ping.Send can EVER return Nothing, but it does seem possible, in which case Reply would be Nothing, which would then cause trouble when you tried to access it. Better yet, that exception would be thrown on a different thread, so it may fit pretty well.
    Hmm yeah I see what you mean.. but why would it throw a nullreferenceexception that is the weird thing.

    It's like it runs runs runs... it checks each time for a return... I did it based off the list of the class and the icmp echo/ping error responses.

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    Yeah. It isn't clear that ping.Send CAN return Nothing, but if it did, then that is the exception you would get, because reply would be Nothing, so when you then make calls like:

    reply.Address.ToString

    you'd get a NullReference exception. I'm not sold on that being the source of the problem, but there really aren't a lot of options in that code. Most of the objects you work with are things that simply CAN'T be Nothing, so you can rule them out. That one example has the advantage that:

    a) It would cause that type of exception if ping.Send returned Nothing.
    b) It is in a different thread, which might account for the strange behavior of the exception, as Grimfort noted.
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    vb Code:
    1. Dim Execute As New Thread(Sub()
    2.                                       Do While Closeme = False
    3.                                           Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
    4.                                           Try
    5.                                               Select Case ping.Send(Address).Status
    6.                                                   Case Net.NetworkInformation.IPStatus.Success
    7.                                                       sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, reply.Address.ToString, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl))
    8.                                                       PacketReceived += 1
    9.                                                       Thread.Sleep(1000)
    10.                                                       'Case Net.NetworkInformation.IPStatus.packettoosmall
    11.                                                       '    sbU("Reply buffer too small." & vbNewLine)
    12.                                                       '    Thread.Sleep(1000)
    13.                                                   Case Net.NetworkInformation.IPStatus.DestinationNetworkUnreachable
    14.                                                       sbU("Destination net unreachable." & vbNewLine)
    15.                                                       Thread.Sleep(1000)
    16.                                                   Case Net.NetworkInformation.IPStatus.DestinationHostUnreachable
    17.                                                       sbU("Destination host unreachable." & vbNewLine)
    18.                                                       Thread.Sleep(1000)
    19.                                                   Case Net.NetworkInformation.IPStatus.DestinationProtocolUnreachable
    20.                                                       sbU("Destination protocol unreachable." & vbNewLine)
    21.                                                       Thread.Sleep(1000)
    22.                                                   Case Net.NetworkInformation.IPStatus.DestinationPortUnreachable
    23.                                                       sbU("Destination port unreachable." & vbNewLine)
    24.                                                       Thread.Sleep(1000)
    25.                                                   Case Net.NetworkInformation.IPStatus.NoResources
    26.                                                       sbU("No resources." & vbNewLine)
    27.                                                       Thread.Sleep(1000)
    28.                                                   Case Net.NetworkInformation.IPStatus.BadOption
    29.                                                       sbU("Bad option." & vbNewLine)
    30.                                                       Thread.Sleep(1000)
    31.                                                   Case Net.NetworkInformation.IPStatus.HardwareError
    32.                                                       sbU("Hardware error." & vbNewLine)
    33.                                                       Thread.Sleep(1000)
    34.                                                   Case Net.NetworkInformation.IPStatus.PacketTooBig
    35.                                                       sbU("Packet too big." & vbNewLine)
    36.                                                       Thread.Sleep(1000)
    37.                                                   Case Net.NetworkInformation.IPStatus.TimedOut
    38.                                                       sbU("Request timed out." & vbNewLine)
    39.                                                   Case Net.NetworkInformation.IPStatus.BadHeader
    40.                                                       sbU("Bad request" & vbNewLine)
    41.                                                       Thread.Sleep(1000)
    42.                                                   Case Net.NetworkInformation.IPStatus.BadRoute
    43.                                                       sbU("Bad route" & vbNewLine)
    44.                                                       Thread.Sleep(1000)
    45.                                                   Case Net.NetworkInformation.IPStatus.TtlExpired
    46.                                                       sbU("Reply from " & reply.Address.ToString & " The time to live (TTL) expired in transit." & vbNewLine)
    47.                                                       PacketReceived += 1
    48.                                                       Thread.Sleep(1000)
    49.                                                   Case Net.NetworkInformation.IPStatus.TtlReassemblyTimeExceeded
    50.                                                       sbU("The time to live expired during fragment reassembly." & vbNewLine)
    51.                                                       Thread.Sleep(1000)
    52.                                                   Case Net.NetworkInformation.IPStatus.ParameterProblem
    53.                                                       sbU("Parameter problem" & vbNewLine)
    54.                                                       Thread.Sleep(1000)
    55.                                                   Case Net.NetworkInformation.IPStatus.SourceQuench
    56.                                                       sbU("Source quench - Datagrams are arriving too fast to be processed and datagrams may have been discarded." & vbNewLine)
    57.                                                       Thread.Sleep(1000)
    58.                                                       'Case Net.NetworkInformation.IPStatus.OptionTooBig
    59.                                                       '    sbU("Option too big." & vbNewLine)
    60.                                                       '    Thread.Sleep(1000)
    61.                                                   Case Net.NetworkInformation.IPStatus.BadDestination
    62.                                                       sbU("Bad destination." & vbNewLine)
    63.                                                       Thread.Sleep(1000)
    64.                                                       'Case Net.NetworkInformation.IPStatus.NegotiatingIPSEC
    65.                                                       '    sbU("Negotiating IPSEC." & vbNewLine)
    66.                                                       '    Thread.Sleep(1000)
    67.                                                   Case Net.NetworkInformation.IPStatus.Unknown
    68.                                                       sbU("A general failure. This error can be returned for some malformed ICMP packets." & vbNewLine)
    69.                                                       Thread.Sleep(1000)
    70.                                               End Select
    71.                                               If reply.RoundtripTime < MinimumMS Then MinimumMS = reply.RoundtripTime
    72.                                               If reply.RoundtripTime > MaximumMS Then MaximumMS = reply.RoundtripTime
    73.                                               TotalMS += reply.RoundtripTime
    74.                                               PacketsSent += 1
    75.                                               If Closeme = True Then
    76.                                                   PacketLost = PacketsSent - PacketReceived
    77.                                                   sbU(vbNewLine & String.Format("Ping statistics for {0}:" & vbNewLine & vbTab & _
    78. "Packets: Sent = {1} Received = {2} Lost = {3} ({4}% loss)" & vbNewLine, Address, PacketsSent, PacketReceived, PacketLost, (PacketLost / PacketsSent * 100)))
    79.                                                   sbU(vbNewLine & String.Format("Approximate round trip times in milli-seconds:" & vbNewLine & vbTab & _
    80. "Minimum = {0}ms, Maximum = {1}ms, Average = {2}ms" & vbNewLine, MinimumMS, MaximumMS, Math.Ceiling(TotalMS / PacketsSent)))
    81.                                                   Completion = True
    82.                                               End If
    83.                                           Catch ex As System.Net.NetworkInformation.PingException
    84.                                               MsgBox(ex.InnerException.Message)
    85.                                           End Try
    86.                                       Loop
    87.  
    88.                                   End Sub)
    89.         Execute.Start()

    This is the overall ping thread.

    Edit: useless.. the formatting of the code gets screwed up.

    I do get what you're saying if I do a .tostring it may fail with a null right? but it makes no sense.. and then the networkinformation exceptions that are possible I try to account for all of them hmm...

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    An unhandled exception of type 'System.NullReferenceException' occurred in TDLHelpdeskToolkit.exe

    Additional information: Object reference not set to an instance of an object.I MANAGED to make it crash yesssss.... lol... i had 4 ping windows open... and it failed on this line:

    vb Code:
    1. sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, reply.Address.ToString, reply.Buffer.Length, reply.RoundtripTime, reply.Options.Ttl))

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    Then that's almost certainly the issue. You could test whether reply Is Nothing just before that line. Of course, you'd write a different message if it WAS Nothing, but to start off with, it would be really useful just to know that it COULD be Nothing, so just having an
    Code:
    If reply Is Nothing Then
     'log that fact
    Else
     'Your sbU call here
    End If
    would really be interesting. That would be more efficient than catching the NullReference exceptions, too.
    My usual boring signature: Nothing

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    So I did a simple check for it now and will try again and see when it fails...

    I declared a few variables instead.

    vb Code:
    1. Dim replyaddress, bufferr, roundtrip, ttl

    and changed the problem line to include the variables:

    vb Code:
    1. sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, replyaddress, bufferr, roundtrip, ttl))


    The check simple msgbox

    vb Code:
    1. If reply.Address.ToString = Nothing Then
    2.                                                           replyaddress = ""
    3.                                                           MsgBox("addressisnothing")
    4.                                                       Else
    5.                                                           replyaddress = reply.Address.ToString
    6.                                                       End If
    7.                                                       If reply.Buffer.Length = Nothing Then
    8.                                                           bufferr = ""
    9.                                                           MsgBox("bufferreplylenghtisnothing")
    10.                                                       Else
    11.                                                           bufferr = reply.Buffer.Length
    12.                                                       End If
    13.                                                       If reply.RoundtripTime = Nothing Then
    14.                                                           roundtrip = ""
    15.                                                           MsgBox("roundtripisnothing")
    16.                                                       Else
    17.                                                           roundtrip = reply.RoundtripTime
    18.                                                       End If
    19.                                                       If reply.Options.Ttl = Nothing Then
    20.                                                           ttl = ""
    21.                                                           MsgBox("ttlisnothing")
    22.                                                       Else
    23.                                                           ttl = reply.Options.Ttl
    24.                                                       End If
    Last edited by a_ahmed; Oct 17th, 2014 at 03:02 PM.

  19. #19
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    That isn't sufficient...if I can read the darn code formatting correctly. You are checking for all the parts of reply, which is a good thing to do (I hadn't actually looked at that, but it's a good thing to check for), but you aren't checking whether reply itself is Nothing. If reply is Nothing, then you'll get that NullReference exception as soon as you try to access any properties, which means that:

    If reply.Address.ToString = Nothing Then

    will throw an exception because you can't access the .Address property of Nothing (since it has no such property).
    My usual boring signature: Nothing

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    And i made it happen again:

    An unhandled exception of type 'System.NullReferenceException' occurred in TDLHelpdeskToolkit.exe

    Additional information: Object reference not set to an instance of an object.

    on this line:

    If reply.Address.ToString = Nothing Then

    So its throwing a null exception on the nothing line

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Well its returning success though as I have a case select:

    vb Code:
    1. Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
    2.                                           Try
    3.                                               Select Case ping.Send(Address).Status
    4.                                                   Case Net.NetworkInformation.IPStatus.Success

    It's in this status response that if it's ipstatus.success that i do that line

    vb Code:
    1. sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, replyaddress, bufferr, roundtrip, ttl))

    That it was originally failing on.

    Edit: I don't know why the code formatting is so squeezed down should be wider in the post...
    Last edited by a_ahmed; Oct 17th, 2014 at 03:14 PM.

  22. #22
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Fixing program crashes that do not throw an exception

    The code you posted never exits so is this a simply ping flooding? May i ask why do you need to do this. My concern is genuine

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    ^You know you always have stupid conclusions, I don't know why that is.

    It's a continuous ping, I guess you never heard of that huh? Why would I put in a one second delay if it was a 'flood'. If you actually bothered to read there is a close button.

  24. #24
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    Well, I'm curious as to why you'd be doing the ping, too. The only times I've ever seen ping used was very rarely for diagnostics and mostly just for curiosity. Since I haven't needed to deal with those diagnostics, and I have enough other things to be curious about, I've never dealt with ping at all. For that reason alone, I'm curious as to what you would do with this.

    However, that has nothing to do with the problem...except I'm not clear whether or not there is a problem any longer. From your post #21, is the problem solved?
    My usual boring signature: Nothing

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    It's a helpdesk dashboard tool I built. Specifically the pings are used to ping network devices. I automated all helpdesk tasks into the tool. I'd love to share some bits of it, but it's confidential as it's for a specific well known company... did it voluntarily when I saw what a mess their helpdesk and IT infrastructure was. Needless to say a worthwhile effort.

    When reporting to a vendor, the results are necessary. redirecting ping.exe output was more complicated than this (didn't get desired effect either). Basically on each device there's a quick continuous ping button (ping ipaddress -t) which starts a new process for ping ipaddress -t, however if you close the window you don't get the ping results and you also can't copy/paste from a console window.

    Solved it by building my own that emulates ping.exe, and a cool learning experience too.

    As far as the problem, I isolated it to failing on that one line, but the problem is getting the program to crash for me to doublecheck test lol... I got lucky that i managed to make it crash haha... it is spontaneous which is hard to deal with...

  26. #26
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Fixing program crashes that do not throw an exception

    Quote Originally Posted by a_ahmed View Post
    It just crashed on me, I clicked debug and this is what I get:

    An unhandled exception of type 'System.NullReferenceException' occurred in Helpdesk Toolkit.exe

    Additional information: Object reference not set to an instance of an object.

    ...

    The thing is it is random could happen anytime but pretty rare but when it happens it happens... I had the program open 6 hours and no issues.. and now...

    Edit: The thing is it's not giving me the code obviously because its the exe i was debugging...
    Not reading all the posts on here ... but if you can distribute the pdb files with your exe it will actually show you the call stack (with line numbers) when you goto the details of the error so you can see exactly where the error occurred!
    ... much more helpful!

    Kris

  27. #27
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Fixing program crashes that do not throw an exception

    But why would a major company ask a beginner to write an application? I just can't see the logic. I asked nicely in a professional manner and you responded quite rude. I signed up to help and protect this forum. Am i not allowed to be worried for it?

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Quote Originally Posted by ident View Post
    But why would a major company ask a beginner to write an application? I just can't see the logic. I asked nicely in a professional manner and you responded quite rude. I signed up to help and protect this forum. Am i not allowed to be worried for it?
    Why do you ask dumb questions?!?! You are constantly annoying in every damn thread not just me but others. Not giving useful responses or even relavent responses half the time. Sometimes your response is totally irrelavent to what OP even asks because you don't even READ what is stated.

    Why!? Because I decided to do something volontarily useful. Because I have ten years of IT experience and while I may not be an expert coder with ten years of experience, I have more than ten years of experience understanding syntax and programming logic, so if I am learning .NET what business is it to you? I wanted to make the place a better place. Happy? What have you done for anybody?

    You wouldn't know 'professional' if it hit you in the face. I have no idea how old you are, but you don't have a damn clue how to communicate. I think you just like to post as much as possible to make yourself feel important or to get extra posts on this forum.

    Stop responding to my threads, I already reported your annoying posts multiple times. Unless you have something damn useful to contribute for once. Only once and I swear only once have you ever contributed to any of my threads.

    Stay the hell away from me with your dumb responses, starting to piss me off. I am not going to 'hack the world'. Why the hell would I be writing a flooder when there are so many out there?

    Now buzz off!

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    And what has this 'beginner' achieved with the tool?

    •Complete automation of all support tasks with few clicks. Things that used to take 10-15 minutes now take a minute or even less.
    •Built in active directory tools and functions for users and computers without the need to install AD users and computers, plus runs and performs faster than microsoft's tools.
    •Everything tailored for the environment we're.
    •Enumeration of stores and all network devices, troubleshooting tools (ping is just one of them) no need to write out commands, everything again in front of you.
    •Instant enumeration of store data from SQL
    •Automation of installation of software AND automation of a variety of software again cutting down 5 to 10 minutes of work.
    Built in active directory functions no need for users and computers for agents to fiddle with. Speeding up user searches. Everything in front of the user.
    •Encryption of accounts data

    I can go on and on. Remote printer installs, automation of remote connections, execution of remote scripts, and so on and so forth. Basically everything necessary for support in one tool, saving 5-10 minutes per task, in some cases saving 20 minutes of manual work.

    I understand how support works, I understand infrastructure, activedirectory, servers, so being pro-active may be 'newb' to you, but I did what I did and I come on here for help not for idiotic criticism.

    When I get stuck or need a second opinion I ask a question on here or for help. Not to be drilled about WHY I am doing something.

    So while I may be a 'newb' to you, WHY would I do it? HOW are your questions even relevant to my thread?
    Last edited by a_ahmed; Oct 19th, 2014 at 05:38 PM.

  30. #30

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    I apologize for going off, but this ident guy has been following me around and responding in the same useless manner over and over again. I'm pretty pissed off about it already. More than once he said I am building 'hacking tools' and other non-sense.

  31. #31
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Fixing program crashes that do not throw an exception

    I think we got that , trolling aside, is your issue actually fixed?

  32. #32

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Yeah I've isolated the line, but I still want to know WHY it's returning nothing when its returning success status... seems like a glitch or bug in the class.. because prior to getting the results I check for status ... :/

  33. #33
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Fixing program crashes that do not throw an exception

    Quote Originally Posted by ident View Post
    But why would a major company ask a beginner to write an application? I just can't see the logic. I asked nicely in a professional manner and you responded quite rude. I signed up to help and protect this forum. Am i not allowed to be worried for it?
    He's already stated that it's the company he's working for. He might have written this on his spare time to simplify his own job. It's also true that he in his code has a one second delay between the pings so he's obviously not using this to flood anything.

    Quote Originally Posted by a_ahmed View Post
    And i made it happen again:

    An unhandled exception of type 'System.NullReferenceException' occurred in TDLHelpdeskToolkit.exe

    Additional information: Object reference not set to an instance of an object.

    on this line:

    If reply.Address.ToString = Nothing Then

    So its throwing a null exception on the nothing line
    So that's the problem, reply.Address is Nothing so you get the exception when you try to call ToString on that. You should be checking if reply.Address is Nothing (not if it equals Nothing, use the Is keyword)
    Code:
    If reply.Address Is Nothing Then
    The code that you're using to move the form in MouseDown, MouseMove and MouseUp events are not really necessary. All you need is the following in the MouseDown event (and you can delete the code in MouseMove and MouseUp)
    Code:
        DirectCast(sender, Control).Capture = False
        Const WM_NCLBUTTONDOWN As Integer = &HA1
        Const HTCAPTION As Integer = &H2
    
        Dim msg As Message = Message.Create(Me.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero)
        Me.DefWndProc(msg)
    What this code does is removing the mouse capture which happens as soon as you press down the mouse button and instead send a message to the Form that the mouse has been pressed in the titlebar, and that will allow you to move it around.

  34. #34

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Thank you @'Joacim Andersson' I realized that on Friday, I just haven't posted it, I should have used IS rather than equal. That was a bummer on my part.

    I will try out your mouse event suggestion tomorrow at work

    As far as what I mentioned, when I try
    vb Code:
    1. Select Case ping.Send(Address).Status
    2.  
    3. Case Net.NetworkInformation.IPStatus.Success
    is when i Check for the reply.Address.ToString and the buffer.length, so it is strange that upon success it is returning nothing occasionally... which is what was crashing the app.

    The other case Selects look for the other types of status returns, such as, if it's TTL, or destination unreachable, amongst other possible icmp echo responses..

    Also I built this voluntarily to improve the workflow at the helpdesk, when I joined the company IT was a mess, how they managed things, how the infrastructure was put together, the tools at disposal of IT personnel, amongst other things. I had previous VB6 and VBScript experience but was new to .NET. By all means I was no VB6 expert and I let go of VB a long long time ago. Only continued to use VBScript for systems work.

    All helpdesk agents are now using the tool and it saves a heck of a lot of time and headaches. I am really good with automation and scripting with systems work, so it only felt natural for me to build a full fledged tool to automate all support tasks for technical personnel knowing the environment and infrastructure.
    Last edited by a_ahmed; Oct 19th, 2014 at 06:43 PM.

  35. #35
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    The format issues obscured some of the problems with the code. I hadn't seen that case statement before. There's a real problem with that code, if I understand it right. Is this your actual code (I'll try to get the formatting a bit better):

    Code:
    Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
    Try
        Select Case ping.Send(Address).Status
    That was taken from #21, so it may no longer be the case, which is why I ask. The problem is that you call Send to get the Reply, but then in the next line you call Send again, and get a different reply. That is almost certainly a mistake. You may test whatever you want on the first reply, but the second reply is never tested in any way. Therefore, if the second call to Send doesn't return what you want, you will get the exception. You should be calling Send only one time, then switching on the value in reply rather than calling Send a second time.
    My usual boring signature: Nothing

  36. #36

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    Hmm I thought I had to declare it then check like so.. but you're making a lot of sense I'll have to look into this tomorrow too.

    However, the error is still happening within the case select not on the declaration. It was happening after I get a success status response which is why it was weird. Look at my above post. When I get the .success within it is where I had the line that was causing the whole screw up; trying to output with the line is where it was failing after the fact that it was a case success.

  37. #37
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: Fixing program crashes that do not throw an exception

    I can't make any sense out of that last paragraph. It was from looking at the snippet in the last post that I realized that the Select Case was a potential source of the problem. Now you kind of suggest that the snippet you posted wasn't what was actually running. The first line of the snippet is the problem. The failure may not occur on that line, but on one of the case statements, as the situation is an odd one, but that doesn't change the fact that the first line in that snippet is bad in all circumstances. If that snippet isn't the actual code you were running, why show us? But if it was the actual code, then that first line is a problem.
    My usual boring signature: Nothing

  38. #38

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: Fixing program crashes that do not throw an exception

    You're right I overlooked this. Looks like this was my biggest blunder. Thank you

    Changed to:

    vb Code:
    1. Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
    2. Try
    3. Select Case reply.Status
    4.  Case Net.NetworkInformation.IPStatus.Success

  39. #39

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: [RESOLVED] Fixing program crashes that do not throw an exception

    @'Joacim Andersson' just wanted to respond regarding the mouse down event and moving the window.

    The difference between how your code works and mine is that my code would drag the window around live, the code you gave me is the standard windows drag (I have visual settings set to performance so it shows a rectangle when moving rather than drag).

    Just wanted to note that But thank you. Less code = better.

  40. #40

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    353

    Re: [RESOLVED] Fixing program crashes that do not throw an exception

    Okay one more find, the above code for the mouse down causes a problem.

    I have mouse click events, they are no longer working. For example some labels where I click to copy to clipboard.

    I also have the tab control a point of moving, but when you click it no longer opens the tab page.

    So this code will not work in this instance.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width