我正在使用服務器端活動x控件進行分頁(http://activexperts.com/xmstoolkit/)。下面的代碼工作發現在Windows 2003服務器,但現在我們搬到了2008年的窗戶和我收到以下錯誤:.Net錯誤 - System.AccessViolationException:嘗試讀取或寫入受保護的內存
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at AXmsCtrl.PagerProtocolSnppClass.Clear() at _Default.Button1_Click(Object sender, EventArgs e) in D:\Apps\pagetest\Default.aspx.vb:line 15
我已經搜索並閱讀不同的線程,但我不能找到解決辦法。在此先感謝您的幫助。
下面是代碼:
Partial Class _Default
Inherits System.Web.UI.Page
Private objSnppProtocol As PagerProtocolSnpp = New PagerProtocolSnpp
Private objPagerMessage As PagerMessage = New PagerMessage
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
objPagerMessage.Clear()
objPagerMessage.Recipient = "12345"
objPagerMessage.Data = "Testing send page."
objSnppProtocol.Clear()
objSnppProtocol.Server = "111.111.11.11"
objSnppProtocol.ServerPort = System.Int32.Parse("446")
objSnppProtocol.ServerTimeout = 2000
objSnppProtocol.ProviderPassword = "2125551212 2125551212"
objSnppProtocol.LogFile = Server.MapPath("log.txt")
' Send
objSnppProtocol.Send(objPagerMessage)
UpdateResult(objSnppProtocol.LastError, objSnppProtocol.ProviderResponse)
Catch exc As Exception
Response.Write("<br><font color='maroon'><strong>Paging ERROR:</strong></font><br>" & exc.ToString() & "<br>Trace: " & exc.StackTrace.ToString())
End Try
End Sub
Private Sub UpdateResult(ByVal numResult As System.Int32, ByVal strResponse As String)
ctlResult.Text = numResult.ToString() & ": " & objSnppProtocol.GetErrorDescription(numResult)
ctlResponse.Text = strResponse
End Sub
End Class
遠離匈牙利符號 - MS推薦人們在2003年停止:)不需要任何東西的'obj' - 現在一切都基本上是一個對象。使用名稱來表示其目的。恩。而不是objSnppProtocol使用snnpProtocol – 2011-06-17 01:39:26
OMG ...我認爲訪問衝突已被棄用(永遠不會再被看到)異常。從未想到有一天我會發現.net中存在這樣的例外。對我來說這是一個悲傷的日子。 – 2011-06-17 01:42:59
@Miguel - 他們基本上是除非你做一個不安全的操作,或處理非託管代碼。你仍然可以通過互操作,糟糕的編組等等 - 但是然後你跨越本機/託管代碼之間的界限。在這種情況下,它是一個ActiveX控件。 – 2011-06-17 03:39:11