2 Replies Latest reply on Oct 15, 2013 9:32 PM by akenyon

    PISDK Access Violation

    akenyon

      Hi,

       

      We're developing an application that reads data from an older SQL server and back fills the data in a PI collective. The application begins to write data to PI before crashing with an Access Violation Exception thrown by the PISDK. The exception seems to occur randomly; it doesn't seem to occur at any specific point or at any specific time. Originally we thought the issue occurred because we were using two background threads to concurrently write points to our PI Collective, after changing the application to write point by point the exception still occurs. Is there a way to avoid this issue? We're using the PISDK v1.4.2.445 with our application, we're considering rewriting using the AFSDK, obviously our concern is that the error still occurs after we rewrite the application.

       

       

       

      Here's the last bit of the Call Stack:

       

      ntdll.dll77466d20

       

      piskd.dll!CComClassFactorySingletonPerThread<CPISDK>::RemoveThread()

       

      pisdk.dll!CComObjSingletonPerThread<CPISDK>::Release()

       

      pisdk.dll!IsPISDKGood()

       

      pisdk.dll!CComClassFactorySingletonPerThread<CPISDK>::CreateInstance()

       

       

       

      The function writing data to PI

       
      public static in InsertValues(string PISystem, string tag, List<PIValue> data)
      {
           try
           {
                PISDK.Server srv;
                PISDK.PISDK = new PISDK.PISDK();
                Srv = Pisdk.Servers[PISystem};
                srv.Open()
      
                var pValues = new PISDK.PIValues();
                pValues.ReadOnly = false;
                
                foreach(var item in data)
                {
                     pValues.Add(item.TimeStamp, item.Value, null);
                }
                pValues.ReadOnly = true;
                Srv.PIPoints[tag].Data.UpdateValues(pValues, DataMergeConstants.dmReplaceDuplicates);
                Srv.Close();
                return 0;
           }
           catch (Exception ex)
           {
                return -1;
           }
      }
      

       

        • Re: PISDK Access Violation
          iperetsman

          Hi Alan,

           

          There exists a possibility of an object being prematurely reclaimed by the garbage collector when there are no references to the object in .Net managed code or data, but the object is still in use in unmanaged code. This would trigger an unintentional object release possibly resulting in a crash.  However this situation can be mitigated by the use of the garbage collector’s KeepAlive  method. The purpose of the KeepAlive method is to ensure the existence of a reference to an object that is at risk of being prematurely reclaimed by the garbage collector. See PISDK help topic “Using the PI-SDK with Microsoft .Net” for further details. Not sure if this would  address your issue, but it is definitely worth a try.

           

          Also, have you tried adding [STAThread] attribute to you main module?  (PISDK help topic “Using the PI-SDK with Microsoft .Net”  has an example of using STAThread attribute)

           

          Isaak

            • Re: PISDK Access Violation
              akenyon

              Unfortunately the KeepAlive method didn't seem to fix the problem. We decided we would switch over the the AFSDK and so far the application has been stable for the past few hours. Instead of writing to the collective we are writing to the primary and manually copying the archive to the secondary. We didn't try the [STAThread] attribute so I can't say if this would have been a solution to our problem. Thank you for the suggestion Isaak.