我得到這個錯誤,當我運行我的程序:對象變量還是有塊變量未設置?
型「System.NullReferenceException」的第一次機會異常出現在Microsoft.VisualBasic.dll中
對象變量或與塊變量未設置
這裏是我的代碼:
Dim rt As String = ""
Dim out As String
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
Dim time As Date
time = Now()
Try
wRequest = WebRequest.Create(Address)
wRequest.Timeout = 10000
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Catch wex As WebException
Dim status As WebExceptionStatus = wex.Status
If status = WebExceptionStatus.Timeout Then
MessageBox.Show("Could not establish a connection to the selected exchange server.", "Connection Timed Out", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf status = WebExceptionStatus.ConnectFailure Then
MessageBox.Show("Could not establish a connection to the selected exchange server.", "Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf status = WebExceptionStatus.ProtocolError Then
MessageBox.Show("Could not establish a connection to the selected exchange server.", "Connection Protocol Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Try
你能發佈異常的完整堆棧跟蹤嗎? – antiduh
@antiduh我對VB.net有點新,我怎麼能在VS 2012中做到這一點?在某處設置一箇中斷點? –