richs04

Exception thrown on UpdateValue

Discussion created by richs04 on Sep 8, 2010
Latest reply on Nov 19, 2010 by cescamilla

The following method works in a test dialog app but fails in my console app.  All the passed values are correct.

private void StorePIPoint(UInt32 Vid, Object Value, Int32 Quality, string TagName, PITimeServer.PITimeFormat ts)
{
    PISDK.PIPoints myPoints = m_SDK.Servers.DefaultServer.PIPoints;                    // PIPoints collection of server
    PISDK.PIPoint snapPoint = null;                  // PI point
    PISDK.PIValue snapValue = new PIValue();  // PI Value
    PISDKCommon.PIAsynchStatus aStat = new PISDKCommon.PIAsynchStatus();
    Object x = new Object();

    x = (Quality > 1) ? 1 : 0;
    try
    {
        snapPoint = myPoints["?" + Vid];
        snapValue.Value = Value;
        snapValue.TimeStamp = (PITimeServer.PITime)ts;
        snapValue.ValueAttributes.Add("questionable", ref x);
        snapPoint.Data.UpdateValue(snapValue, ts, DataMergeConstants.dmInsertDuplicates, aStat);
    }
    catch (Exception e)
    {
        Link_Msg.Record_Msg("Link:StorePIPoint Failed to store " + TagName + ". " + e.Message,
            RTimeInterface.MSGTYPE_APP_ERROR, RecordMessage.MSGTYPE.BOTH);
        }
    }
}

What was in the exception.

 

e {"Unable to add to a PIValues collection.  Failed to clone ValueAttribute"}
+ [System.Runtime.InteropServices.COMException] {"Unable to add to a PIValues collection.  Failed to clone ValueAttribute"}
  _className null string
  _data null System.Collections.IDictionary
  _dynamicMethods null object
  _exceptionMethod null System.Reflection.MethodBase
  _exceptionMethodString null string
  _helpURL "C:\\Program Files\\pipc\\PISDK\\..\\Help\\pisdk.chm" string
  _HResult -2147220028 int
+  _innerException null System.Exception
  _message "Unable to add to a PIValues collection.  Failed to clone ValueAttribute" string
  _remoteStackIndex 0 int
  _remoteStackTraceString null string
  _source "pisdk.dll" string
+  _stackTrace {sbyte[48]} object {sbyte[]}
  _stackTraceString null string
  _xcode -532459699 int
+  _xptrs 0 System.IntPtr
+  Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
  HelpLink "C:\\Program Files\\pipc\\PISDK\\..\\Help\\pisdk.chm" string
  HResult -2147220028 int
+  InnerException null System.Exception
  IsTransient false bool
  Message "Unable to add to a PIValues collection.  Failed to clone ValueAttribute" string
  Source "pisdk.dll" string
  StackTrace "   at PISDK.PIDataClass.UpdateValue(Object newValue, Object TimeStamp, DataMergeConstants MergeType, PIAsynchStatus asynchStatus)\r\n   at pmax.Link.StorePIPoint(UInt32 Vid, Object Value, Int32 Quality, String TagName, PITimeFormat ts) in C:\\Development\\pmax\\pmax\\Link.cs:line 587" string
+  TargetSite {Void UpdateValue(System.Object, System.Object, PISDK.DataMergeConstants, PISDKCommon.PIAsynchStatus)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+  Static members

Outcomes