【发布时间】:2013-05-03 16:17:52
【问题描述】:
大家早安,
我正在将 VS2010 与 VB 一起使用,并且试图在我的 Web 应用程序中进行 ping 测试。为了做到这一点并测试它是否有效,我简单地创建了一个按钮,当点击时应该 ping 指定的 IP 地址。
我相信按钮的代码应该可以正常工作。我唯一的问题是我的网页上出现以下错误消息...
System.NullReferenceException: Object reference not set to an instance of an object.
它在 cole 线上的错误...
Console.WriteLine("Address: {0}", vPingReply.Address)
我认为这是由于需要为 .Address 和 .Status 对象设置“属性”。我不太确定我是否正确添加了这些,因为我已经添加了一些属性,但是当我运行页面时我仍然遇到同样的问题?
有人可以看看和建议吗?
这是我的完整代码...
Imports Microsoft.VisualBasic
Imports System.Text
Imports System.Net.NetworkInformation
Imports System.Net.NetworkInformation.PingReply
Partial Class Ping
Inherits System.Web.UI.Page
Private mSend As PingReply
Private Property Send(p1 As String) As PingReply
Get
Return mSend
End Get
Set(value As PingReply)
mSend = value
End Set
End Property
Private mAddress As PingReply
Private Property Address(p2 As String) As PingReply
Get
Return mAddress
End Get
Set(value As PingReply)
mAddress = value
End Set
End Property
Private mStatus As PingReply
Private Property Status(p3 As String) As PingReply
Get
Return mStatus
End Get
Set(value As PingReply)
mStatus = value
End Set
End Property
Protected Sub btnPing_Click(sender As Object, e As System.EventArgs) Handles btnPing.Click
Dim vPing As New Ping
Dim vPingReply As PingReply = vPing.Send("xxx.xx.xxx.xx")
Console.WriteLine("Address: {0}", vPingReply.Address)
Console.WriteLine("Status: {0}", vPingReply.Status)
End Sub
End Class
非常感谢任何帮助。
贝蒂。
【问题讨论】:
-
如果您在调试中检查“vPingReply.Address”的值,它是否设置为任何值?
-
@Jacooobley,我已经调试了页面和 vPing.Send 和 vPingReply 都 = 没有。
标签: asp.net vb.net visual-studio-2010 visual-studio visual-studio-2008