-
Oct 17th, 2014, 11:52 AM
#1
Thread Starter
Hyperactive Member
[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...
-
Oct 17th, 2014, 12:00 PM
#2
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.
-
Oct 17th, 2014, 12:04 PM
#3
Thread Starter
Hyperactive Member
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.
-
Oct 17th, 2014, 12:48 PM
#4
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.
-
Oct 17th, 2014, 01:36 PM
#5
Thread Starter
Hyperactive Member
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..
-
Oct 17th, 2014, 01:40 PM
#6
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.
-
Oct 17th, 2014, 01:45 PM
#7
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
-
Oct 17th, 2014, 01:47 PM
#8
Thread Starter
Hyperactive Member
Re: Fixing program crashes that do not throw an exception
vb Code:
Imports System.Net.NetworkInformation Imports System.Net Imports System.Threading Imports System.Text Imports System.Net.NetworkInformation.IcmpV4Statistics Public Class PingWindow Public Closeme = False Public Completion = False Public Unreachable = False Public ClipBoarderC = False Delegate Sub SetTextCallback(ByVal text As String) Private Sub PingWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Icon = My.Resources.PingIcon 'SetWindowText(Me.Handle.ToInt32, "Pinging") End Sub Public Sub sbU(ByVal text As String) If ConsoleTxtBox.InvokeRequired Then Dim d As New SetTextCallback(AddressOf sbU) Try Me.Invoke(d, New Object() {text}) Catch ex As System.ObjectDisposedException End Try Else ConsoleTxtBox.Text += text Try ConsoleTxtBox.SelectionStart = ConsoleTxtBox.Text.Length ConsoleTxtBox.ScrollToCaret() Catch ex As System.ObjectDisposedException End Try End If End Sub Private Sub EK3Email_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown, WindowTitleLabel.MouseDown, ConsoleTxtBox.MouseDown drag = True 'Sets the variable drag to true. mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable mousey End Sub Private Sub EK3Email_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove, WindowTitleLabel.MouseMove, ConsoleTxtBox.MouseMove 'If drag is set to true then move the form accordingly. If drag Then Me.Top = Windows.Forms.Cursor.Position.Y - mousey Me.Left = Windows.Forms.Cursor.Position.X - mousex End If End Sub Private Sub EK3Email_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp, WindowTitleLabel.MouseUp, ConsoleTxtBox.MouseUp drag = False 'Sets drag to false, so the form does not move according to the code in MouseMove End Sub Sub Pinger(ByVal Address As String, ByVal WindowTitle As String) WindowTitleLabel.Text = "[ " & WindowTitle & " ]" SetWindowText(Me.Handle.ToInt32, WindowTitle) Closeme = False Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Dim buffer() As Byte = Encoding.ASCII.GetBytes(data) Dim timeout As Integer = 1000 Dim ip As IPAddress = Nothing Dim ping As New System.Net.NetworkInformation.Ping Dim options As New System.Net.NetworkInformation.PingOptions options.Ttl = 128 options.DontFragment = True If CheckForAlphaCharacters(Address) Then Try ip = Dns.GetHostEntry(Address).AddressList(0) sbU("Pinging " & Address & " [" & ip.ToString & "] with " & buffer.Length & " bytes of data:" & vbNewLine) Catch ex As System.Net.Sockets.SocketException sbU("Ping request could not find host " & Address & ". Please check the name and try again.") Completion = True Unreachable = True Exit Sub End Try Else sbU("Pinging " & Address & " with " & buffer.Length & " bytes of data:" & vbNewLine) End If Dim PacketsSent = 0 Dim PacketReceived = 0 Dim PacketLost = 0 Dim MinimumMS = 9999 Dim MaximumMS = -1 Dim TotalMS Dim Execute As New Thread(Sub() Do While Closeme = False Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options) Try Select Case ping.Send(Address).Status Case Net.NetworkInformation.IPStatus.Success 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)) PacketReceived += 1 Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.packettoosmall ' sbU("Reply buffer too small." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationNetworkUnreachable sbU("Destination net unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationHostUnreachable sbU("Destination host unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationProtocolUnreachable sbU("Destination protocol unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationPortUnreachable sbU("Destination port unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.NoResources sbU("No resources." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadOption sbU("Bad option." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.HardwareError sbU("Hardware error." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.PacketTooBig sbU("Packet too big." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TimedOut sbU("Request timed out." & vbNewLine) Case Net.NetworkInformation.IPStatus.BadHeader sbU("Bad request" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadRoute sbU("Bad route" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TtlExpired sbU("Reply from " & reply.Address.ToString & " The time to live (TTL) expired in transit." & vbNewLine) PacketReceived += 1 Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TtlReassemblyTimeExceeded sbU("The time to live expired during fragment reassembly." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.ParameterProblem sbU("Parameter problem" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.SourceQuench sbU("Source quench - Datagrams are arriving too fast to be processed and datagrams may have been discarded." & vbNewLine) Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.OptionTooBig ' sbU("Option too big." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadDestination sbU("Bad destination." & vbNewLine) Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.NegotiatingIPSEC ' sbU("Negotiating IPSEC." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.Unknown sbU("A general failure. This error can be returned for some malformed ICMP packets." & vbNewLine) Thread.Sleep(1000) End Select If reply.RoundtripTime < MinimumMS Then MinimumMS = reply.RoundtripTime If reply.RoundtripTime > MaximumMS Then MaximumMS = reply.RoundtripTime TotalMS += reply.RoundtripTime PacketsSent += 1 If Closeme = True Then PacketLost = PacketsSent - PacketReceived sbU(vbNewLine & String.Format("Ping statistics for {0}:" & vbNewLine & vbTab & _ "Packets: Sent = {1} Received = {2} Lost = {3} ({4}% loss)" & vbNewLine, Address, PacketsSent, PacketReceived, PacketLost, (PacketLost / PacketsSent * 100))) sbU(vbNewLine & String.Format("Approximate round trip times in milli-seconds:" & vbNewLine & vbTab & _ "Minimum = {0}ms, Maximum = {1}ms, Average = {2}ms" & vbNewLine, MinimumMS, MaximumMS, Math.Ceiling(TotalMS / PacketsSent))) Completion = True End If Catch ex As System.Net.NetworkInformation.PingException MsgBox(ex.InnerException.Message) End Try Loop End Sub) Execute.Start() End Sub Sub clipboarder() If Me.InvokeRequired Then Me.Invoke(New MethodInvoker(AddressOf clipboarder)) Else Clipboard.SetText(ConsoleTxtBox.Text, TextDataFormat.Text) ClipBoarderC = True End If End Sub Function CheckForAlphaCharacters(ByVal StringToCheck As String) For i = 0 To StringToCheck.Length - 1 If Char.IsLetter(StringToCheck.Chars(i)) Then Return True End If Next Return False End Function Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click Closeme = True If Unreachable = True Then Do While Completion = False Loop Me.Close() Else Dim res As MsgBoxResult = MessageBox.Show("Do you want to copy results to clipboard?", AppTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) If res = MsgBoxResult.Yes Then Dim Execute As New Thread(Sub() Do While Completion = False Loop clipboarder() Me.Close() End Sub) Execute.Start() Else Me.Close() End If End If End Sub Private Sub btnMinimize_Click(sender As Object, e As EventArgs) Handles btnMinimize.Click Me.WindowState = FormWindowState.Minimized End Sub 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.
-
Oct 17th, 2014, 01:53 PM
#9
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)
-
Oct 17th, 2014, 01:58 PM
#10
Thread Starter
Hyperactive Member
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:
If CheckForAlphaCharacters(Address) Then Try ip = Dns.GetHostEntry(Address).AddressList(0) sbU("Pinging " & Address & " [" & ip.ToString & "] with " & buffer.Length & " bytes of data:" & vbNewLine) Catch ex As System.Net.Sockets.SocketException sbU("Ping request could not find host " & Address & ". Please check the name and try again.") Completion = True Unreachable = True Exit Sub End Try Else sbU("Pinging " & Address & " with " & buffer.Length & " bytes of data:" & vbNewLine) End If]
The crash happens while the ping is happening, so it would be after this piece of code,
-
Oct 17th, 2014, 01:58 PM
#11
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
-
Oct 17th, 2014, 02:01 PM
#12
Thread Starter
Hyperactive Member
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
-
Oct 17th, 2014, 02:01 PM
#13
Thread Starter
Hyperactive Member
Re: Fixing program crashes that do not throw an exception
Originally Posted by Shaggy Hiker
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.
-
Oct 17th, 2014, 02:06 PM
#14
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
-
Oct 17th, 2014, 02:09 PM
#15
Thread Starter
Hyperactive Member
Re: Fixing program crashes that do not throw an exception
vb Code:
Dim Execute As New Thread(Sub() Do While Closeme = False Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options) Try Select Case ping.Send(Address).Status Case Net.NetworkInformation.IPStatus.Success 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)) PacketReceived += 1 Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.packettoosmall ' sbU("Reply buffer too small." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationNetworkUnreachable sbU("Destination net unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationHostUnreachable sbU("Destination host unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationProtocolUnreachable sbU("Destination protocol unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.DestinationPortUnreachable sbU("Destination port unreachable." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.NoResources sbU("No resources." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadOption sbU("Bad option." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.HardwareError sbU("Hardware error." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.PacketTooBig sbU("Packet too big." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TimedOut sbU("Request timed out." & vbNewLine) Case Net.NetworkInformation.IPStatus.BadHeader sbU("Bad request" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadRoute sbU("Bad route" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TtlExpired sbU("Reply from " & reply.Address.ToString & " The time to live (TTL) expired in transit." & vbNewLine) PacketReceived += 1 Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.TtlReassemblyTimeExceeded sbU("The time to live expired during fragment reassembly." & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.ParameterProblem sbU("Parameter problem" & vbNewLine) Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.SourceQuench sbU("Source quench - Datagrams are arriving too fast to be processed and datagrams may have been discarded." & vbNewLine) Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.OptionTooBig ' sbU("Option too big." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.BadDestination sbU("Bad destination." & vbNewLine) Thread.Sleep(1000) 'Case Net.NetworkInformation.IPStatus.NegotiatingIPSEC ' sbU("Negotiating IPSEC." & vbNewLine) ' Thread.Sleep(1000) Case Net.NetworkInformation.IPStatus.Unknown sbU("A general failure. This error can be returned for some malformed ICMP packets." & vbNewLine) Thread.Sleep(1000) End Select If reply.RoundtripTime < MinimumMS Then MinimumMS = reply.RoundtripTime If reply.RoundtripTime > MaximumMS Then MaximumMS = reply.RoundtripTime TotalMS += reply.RoundtripTime PacketsSent += 1 If Closeme = True Then PacketLost = PacketsSent - PacketReceived sbU(vbNewLine & String.Format("Ping statistics for {0}:" & vbNewLine & vbTab & _ "Packets: Sent = {1} Received = {2} Lost = {3} ({4}% loss)" & vbNewLine, Address, PacketsSent, PacketReceived, PacketLost, (PacketLost / PacketsSent * 100))) sbU(vbNewLine & String.Format("Approximate round trip times in milli-seconds:" & vbNewLine & vbTab & _ "Minimum = {0}ms, Maximum = {1}ms, Average = {2}ms" & vbNewLine, MinimumMS, MaximumMS, Math.Ceiling(TotalMS / PacketsSent))) Completion = True End If Catch ex As System.Net.NetworkInformation.PingException MsgBox(ex.InnerException.Message) End Try Loop End Sub) 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...
-
Oct 17th, 2014, 02:15 PM
#16
Thread Starter
Hyperactive Member
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:
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))
-
Oct 17th, 2014, 02:24 PM
#17
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
-
Oct 17th, 2014, 02:55 PM
#18
Thread Starter
Hyperactive Member
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:
Dim replyaddress, bufferr, roundtrip, ttl
and changed the problem line to include the variables:
vb Code:
sbU(String.Format("Reply from {0}: bytes={1} time={2}ms TTL={3}" & vbNewLine, replyaddress, bufferr, roundtrip, ttl))
The check simple msgbox
vb Code:
If reply.Address.ToString = Nothing Then replyaddress = "" MsgBox("addressisnothing") Else replyaddress = reply.Address.ToString End If If reply.Buffer.Length = Nothing Then bufferr = "" MsgBox("bufferreplylenghtisnothing") Else bufferr = reply.Buffer.Length End If If reply.RoundtripTime = Nothing Then roundtrip = "" MsgBox("roundtripisnothing") Else roundtrip = reply.RoundtripTime End If If reply.Options.Ttl = Nothing Then ttl = "" MsgBox("ttlisnothing") Else ttl = reply.Options.Ttl End If
Last edited by a_ahmed; Oct 17th, 2014 at 03:02 PM.
-
Oct 17th, 2014, 03:08 PM
#19
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
-
Oct 17th, 2014, 03:09 PM
#20
Thread Starter
Hyperactive Member
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
-
Oct 17th, 2014, 03:10 PM
#21
Thread Starter
Hyperactive Member
Re: Fixing program crashes that do not throw an exception
Well its returning success though as I have a case select:
vb Code:
Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options) Try Select Case ping.Send(Address).Status Case Net.NetworkInformation.IPStatus.Success
It's in this status response that if it's ipstatus.success that i do that line
vb Code:
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.
-
Oct 17th, 2014, 07:50 PM
#22
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
-
Oct 18th, 2014, 08:40 AM
#23
Thread Starter
Hyperactive Member
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.
-
Oct 18th, 2014, 11:48 AM
#24
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
-
Oct 18th, 2014, 10:43 PM
#25
Thread Starter
Hyperactive Member
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...
-
Oct 19th, 2014, 01:18 AM
#26
Re: Fixing program crashes that do not throw an exception
Originally Posted by a_ahmed
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
-
Oct 19th, 2014, 02:20 PM
#27
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?
-
Oct 19th, 2014, 05:16 PM
#28
Thread Starter
Hyperactive Member
Re: Fixing program crashes that do not throw an exception
Originally Posted by ident
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!
-
Oct 19th, 2014, 05:30 PM
#29
Thread Starter
Hyperactive Member
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.
-
Oct 19th, 2014, 05:41 PM
#30
Thread Starter
Hyperactive Member
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.
-
Oct 19th, 2014, 05:51 PM
#31
Re: Fixing program crashes that do not throw an exception
I think we got that , trolling aside, is your issue actually fixed?
-
Oct 19th, 2014, 06:09 PM
#32
Thread Starter
Hyperactive Member
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 ... :/
-
Oct 19th, 2014, 06:25 PM
#33
Re: Fixing program crashes that do not throw an exception
Originally Posted by ident
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.
Originally Posted by a_ahmed
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.
-
Oct 19th, 2014, 06:37 PM
#34
Thread Starter
Hyperactive Member
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:
Select Case ping.Send(Address).Status 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.
-
Oct 19th, 2014, 06:45 PM
#35
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
-
Oct 19th, 2014, 08:51 PM
#36
Thread Starter
Hyperactive Member
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.
-
Oct 19th, 2014, 10:11 PM
#37
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
-
Oct 20th, 2014, 12:23 PM
#38
Thread Starter
Hyperactive Member
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:
Dim reply As System.Net.NetworkInformation.PingReply = ping.Send(Address, timeout, buffer, options)
Try
Select Case reply.Status
Case Net.NetworkInformation.IPStatus.Success
-
Oct 20th, 2014, 02:01 PM
#39
Thread Starter
Hyperactive Member
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.
-
Oct 20th, 2014, 02:25 PM
#40
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|