'Null Reference Exception'

kurt69

Well-known member
Joined
Jan 17, 2006
Messages
78
Location
Australia
Programming Experience
Beginner
Hi long time no see.. as you already know by the title, I finally got myself a copy of visual studio 2005. :)

I've started making an application for my home local area network and what I would like it to be able to do is to give me information (in the form of labels) on:

  • What bandwidth the app is using (upload and download)
  • Latency to host (figured this out already)
  • Total sent and received bytes (only from the application)
  • The network interface the application is using.
I tried using the 101vb samples from MSDN, the networkinfo one, however I'm just not doing something right. (this is for getting the interface name and bytes sent/rcvd. I have no idea where to start on getting the bandwidth.

Please help. Thanks for reading.
 
Personally, I would have given this thread a more apt title, and posted it in the Net/Sockets Forum.

Additionally, you havent been very specific about what the problem is that you are facing, other than you have tried some example from some site, and it doesnt work.
 
Ok sorry.. In the example they have:

The following declarations:
VB.NET:
Private interfaces As NetworkInterface()
    Private _currentInterface As NetworkInterface
    Private WithEvents ping As Ping


This..
VB.NET:
    Private Sub LoadTreeView(ByVal interfaces As NetworkInterface())

        ' Load the details about each network interface into the treeview
        Me.infoTree.BeginUpdate()

        Dim rootNode As TreeNode = New TreeNode
        rootNode.Text = "Network Interfaces"

        If interfaces.GetLength(0) > 0 Then
            For Each networkInterface As NetworkInterface In interfaces

                Dim address As PhysicalAddress = networkInterface.GetPhysicalAddress
                Dim bytes As Byte() = address.GetAddressBytes

                Dim networkInterfaceNode As TreeNode = New TreeNode
                networkInterfaceNode.Text = networkInterface.Name
                networkInterfaceNode.Tag = networkInterface

So I tried declaring those things aswell and then doing something like this:
lblInterface.Text = "Interface: " & _currentInterface.Name

But I get a 'Null Reference Exception' error. So basically I have no idea what to do and I need someone to help me out. Thanks.
 
Have you tried wrapping it in a IsNot Nothing statement..


VB.NET:
If NetworkInterface.Site IsNot Nothing then
...
End If

Actually i can't remember if it has an ISite or not. Either way just do a test for nothing before you use the name property.
 
Back
Top