troubleshooting Question

"Attempted to read or write protected memory" using COM automation from a thread

Avatar of Pber
PberFlag for Canada asked on
Visual Basic.NET
8 Comments1 Solution799 ViewsLast Modified:
I've created an application that uses some COM automation libraries from Symantec called from threadpools.  For the most part it works like a charm.  I make several calls to various other methods within the same libraries without issues.  One method (in the code below) seems to throw this error randomly.  I've tried my bag of tricks on it, but can't seem to figure out why it is throwing this exception.  The error doesn't always happen either.  It seems to happen randomly.  Sometimes just the first few connections, the next time it might not error at all.

Any ideas?

Here's the error/stack trace:

System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
       at VProAuto.ProtectorAutoClass.get_ImageJobs()
       at BESR.clsBESR.GetJobData(Object Callback) in C:\Documents and Settings\pbernardin\My Documents\Visual Studio 2005\Projects\BESR\v1.0.1\BESR\clsBESR.vb:line 67
       at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)  
Public Sub GetJobData(ByVal Callback As Object)

        Dim oCurrentJob As VProObj.ImageJob
        Dim task As PQSCHEDULERLib.Task
        Dim myJob As New STRUCT_BESRJOB
        Dim AgentStatus As VProObj.AgentStatus
        Dim v2iAuto As VProAuto.ProtectorAuto

            v2iAuto = New VProAuto.ProtectorAuto
                AgentStatus = v2iAuto.Status
                myJob.AgentSTATUS = AgentStatus.Description.ToString
                If v2iAuto.LastSystemBackupInterval > 1 Then
                    myJob.Status = False
                    myJob.Status = True
                End If
            Catch ex As Exception

            End Try

                For Each oCurrentJob In v2iAuto.ImageJobs '<-- exception throws here
                        task = oCurrentJob.Task
                        myJob.Task = task.DisplayName
                    Catch ex As Exception
                        'myJob.AgentSTATUS = "Task: " & ex.Message
                    End Try
                        oNetworkLocation = oCurrentJob.Location(oCurrentJob.Volumes(0))
                        myJob.Dest_Path = oNetworkLocation.Path
                        myJob.Dest_UserID = oNetworkLocation.NetworkUser
                    Catch ex As Exception
                        'myJob.AgentSTATUS = ("local: " & ex.Message)
                    End Try
                        oOffsiteLocation = oCurrentJob.offsitecopylocations(0)
                        myJob.Offsite_Path = oOffsiteLocation.Path
                        myJob.OffSite_UserID = oOffsiteLocation.NetworkUser
                    Catch ex As Exception
                        'myJob.AgentSTATUS = ("Offite: " & ex.Message)
                    End Try
            Catch ex As Exception
                myJob.AgentSTATUS = ("General: " & ex.Message)

            End Try
        Catch ex As Exception
            myJob.AgentSTATUS = ex.Message
        End Try
        BESR_Delegate(index, myJob)

    End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros