Select to view content in your preferred language

SOE - attempted to read or write protected memory error

1558
3
11-08-2012 06:28 AM
GaryBushek
Deactivated User
I have some arcobjects code that runs fine when running it directly in visual studio. But it fails when I have it running as an SOE.  It fails in a class where I have a call to search a feature class in 2 different locations based on different spatial filter logic.  I've tried setting the map service to both pooled and not pooled but that probably has nothing to do with it as it had no effect. The error is:

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ESRI.ArcGIS.Geodatabase.IFeatureClass.Search(IQueryFilter filter, Boolean Recycling)"


pFC = strSegFC.Search(pSF, True)


Any ideas?
0 Kudos
3 Replies
RichWawrzonek
Frequent Contributor
By using 'True' in your feature class search call you are creating a recycling cursor. Without seeing all of your code I can't be certain but my guess is that your cursor is going out of scope and you try to reuse the object later. Try setting it to false.
0 Kudos
GaryBushek
Deactivated User
Yes, I tried changing the UseRecycling to false but that didn't help.  I've also wondered if it was due to the fact that I'm calling this from a windows service on my local machine and i'm not sure if there are permission issues. Lastly, when connecting to the workspace i'm using the ArcServer product code to initialize.  Not sure if thats right either.


    
Protected Sub connectToSDE_QRAEdit()

        Log.Log("*********Connecting to QRA workspace**********", _logFileName)

        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Server)

        Dim qraPropSet As New PropertySet()

        Dim qraWorkspaceFactory As IWorkspaceFactory = New SdeWorkspaceFactory
        Dim qraWS_Edit As IWorkspace

        Try
            Dim pAoInitialize As IAoInitialize
            pAoInitialize = New AoInitialize

            Dim licenseStatus As esriLicenseStatus
            Dim productCode As esriLicenseProductCode

            productCode = esriLicenseProductCode.esriLicenseProductCodeArcServer

            licenseStatus = pAoInitialize.Initialize(productCode)

            If (Not (licenseStatus = esriLicenseStatus.esriLicenseCheckedOut)) Then
                Log.LogError("", New Exception("License Initialization Failed error = " & licenseStatus), _logFileName)
                Throw New Exception("License Initialization Failed error = " & licenseStatus)
            End If

            qraPropSet.SetProperty("SERVER", Common.AppSettings("SERVER"))
            qraPropSet.SetProperty("INSTANCE", Common.AppSettings("INSTANCE"))
            qraPropSet.SetProperty("USER", Common.AppSettings("QRA_USER"))
            qraPropSet.SetProperty("PASSWORD", Common.AppSettings("QRA_PASSWORD"))
            qraPropSet.SetProperty("VERSION", Common.AppSettings("VERSION"))
            qraPropSet.SetProperty("AUTHENTICATION_MODE", Common.AppSettings("AUTHENTICATION_MODE"))

            qraWS_Edit = qraWorkspaceFactory.Open(qraPropSet, 0)
            qraEditWorkspace = CType(qraWS_Edit, IFeatureWorkspace)

        Catch ex As Exception
            Log.Log(LogLevel.DetailedInfo, "Error trying to connect to SDE. [1]: " & ex.Message & vbCrLf & ex.StackTrace, _logFileName)
            Log.LogError("Error trying to connect to SDE", ex, _logFileName)
            Throw
        Finally

        End Try

    End Sub
0 Kudos
SalieghAziz
Emerging Contributor

Did you ever figure out what caused the problem, and how to fix it? I am experiencing the same issue now

0 Kudos