AnsweredAssumed Answered

AFCalculation.PercentTrue is throwing random exceptions

Question asked by cteixeira on Jul 23, 2018
Latest reply on May 17, 2019 by cteixeira

Hi all,

 

I'm having trouble while using AFCalculation.PercentTrue. I have a process that analyzes performance equations and searches for activations. It runs fine for a few hours, but at some random point in time, it throws this error:

 

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

   at OSIsoft.PI.Net.UnsafeNativeMethods.SessionManager.RPCSetupAndExecute(IntPtr sessionManager, Int32 sessionId, IntPtr package, IntPtr iob, IntPtr userToken)

   at OSIsoft.PI.Net.Connection.Invoke(OperationHandle handle, RoleEntity& principalRole)

   at OSIsoft.PI.Net.OperationHandle.Invoke()

   at OSIsoft.PI.Net.ServiceOperation.GetExpressionTime(OperationHandle handle, DateTime startTime, DateTime endTime, String expression, Int32 intervalCount, Double& matchTime, Double& percentGood)

   at OSIsoft.PI.Net.PIExpression.TimeTrue(ClientChannel channel, DateTime startTime, DateTime endTime, String expression, Int32 intervalCount, Double& percentGood)

   at OSIsoft.AF.PI.PIServer.CalculatePercentTrue(String expression, AFTimeRange timeRange, AFTimeSpan calculationInterval, AFTimeSpan MinSampleInterval, AFTimestampCalculation timeType, AFValues& PercentGoodResult)

   at OSIsoft.AF.Data.AFCalculation.PercentTrue(Object target, String expression, AFTimeRange timeRange, AFTimeSpan calculationInterval, AFTimeSpan minimumSampleInterval, AFTimestampCalculation timeType, AFValues& percentGood)

 

The process then seems to enter an invalid state and every time I call AFCalculation.PercentTrue before that, it throws me this:

 

System.Threading.LockRecursionException: Recursive read lock acquisitions not allowed in this mode.

   at OSIsoft.AF.PI.PIException.ConvertAndThrowException(PIServer piServer, Exception ex, String message)

   at OSIsoft.AF.PI.PIServer.CalculatePercentTrue(String expression, AFTimeRange timeRange, AFTimeSpan calculationInterval, AFTimeSpan MinSampleInterval, AFTimestampCalculation timeType, AFValues& PercentGoodResult)

   at OSIsoft.AF.Data.AFCalculation.PercentTrue(Object target, String expression, AFTimeRange timeRange, AFTimeSpan calculationInterval, AFTimeSpan minimumSampleInterval, AFTimestampCalculation timeType, AFValues& percentGood)

 

In the machine that runs the process I have:

PI SDK Version: 1.4.7

AF SDK Version: 2.10.0.8628

 

The OSIsoft.AFSDK.dll version is: 2.10.0.8628

 

Could you please help me with this one?  Any tips would be appreciated. Thanks in advance.

Outcomes