AnsweredAssumed Answered

AF SDK 2.10.1.8731 PIPoint.FindPIPoints throws exception when using system.linq Count() method

Question asked by langfom on Mar 13, 2019
Latest reply on Mar 13, 2019 by rdavin

I have upgraded a PI system to the latest versions including the AF SDK now using 2.10.1.8731.  Previously the AF SDK version was 2.8.0.7444

 

I have a custom PI Adapter which consumes messages from a queue.  Due to the high message rate, I cache the points into memory.  I call the FindPIPoints method to retrieve points from our PI Server. This returns a large number of points  and the first thing I do is log the number of points by using the system.linq Count() method.

 

IEnumerable<PIPoint> points = PIPoint.FindPIPoints(server, "PointSource:=SCADA", false);
log.Info("Found " + points.Count() + " SCADA points to cache");
foreach (PIPoint pp in points)
{
     ...process each point
}

 

In version 2.8.0 this worked.

 

In version 2.10.1.8731 the above code throws the following exception at the foreach line

 

Unhandled Exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'StreamQuery'.
   at OSIsoft.PI.Net.StreamQuery.get_Query()
   at OSIsoft.PI.Net.StreamSearch`1..ctor(ClientChannel channel, IEnumerable`1 query, StreamFactory`1 factory, Int32 blockSize, StreamSearchDefau
ltAttributes defaultAttribute, IEnumerable`1 attributes)
   at OSIsoft.PI.Net.StreamDirectory.<FindStreams>d__41`1.MoveNext()
   at OSIsoft.AF.PI.PIPoint.<ExecuteSinglePIPointQuery>d__30.MoveNext()

 

It is common (especially while debugging) to print/log the number of objects returned in a collection.

 

This took me some time to narrow down the cause to the Count() method closing the stream.  Posting here to help others and inform the AF SDK developers.

 

Thanks

Mark

Outcomes