6 Replies Latest reply on Sep 19, 2014 5:14 AM by jhim

    System.InvalidOperationException in Server.UpdateValues


      Hi, I'm helping a partner company programmer on coding issues since he's not able to speak english.


      Right now he's trying to write a code which gets data from a device called TC-NET made by TMEIC.




      The code has a Data Gathering Part which gets data from the source and puts it in a List. The error occurs on the Data Saving part which sends the events in the List to PI. He's using AFSDK 2.6.




      The error message is : “System.InvalidOperationException”


      According to the Engineer, he declared List<AFValue>[] _WRITE_DATA which is an array of AFValue list. The Writing Method is locked and copies the _WRITE_DATA to _FINAL_DATA and then send the events in _FINAL_DATA to PI via For loop. It loops until all the arrays are sent.




                           private void DoWork_Writing()




                                      lock (lockPIData) //The code below is run once in only one thread




                                                lock (lockData) //_WRITE_DATA is shared with data gathering thread so it is locked




                                                           _FINAL_DATA = _WRITE_DATA; //Transfer data <- reading data


                                                           _WRITE_DATA = afvaluesList; //array Initialize




                                                for (int i = 0; i < _FINAL_DATA.Length; i++)




                                                           List<AFValue> val = _FINAL_DATA [ i ];


                                                           if (val.Count == 0) break;


                                                           OSIsoft.AF.AFErrors<AFValue> errors = server.UpdateValues(val, OSIsoft.AF.Data.AFUpdateOption.Insert); //error here!!










      Seems to me, the type of val and UpdateValues required parameter doesn’t match. But I'm not really sure. I need some advice for this code.


      Asked programmer about additional errors but he couldn’t find anything else. Is there a way I could help him? Any advice would be helpful.

        • Re: System.InvalidOperationException in Server.UpdateValues

          Can you give us a little more information?  Has a PIPoint object been associated with each AFValue object in the list of AFValues called val in your sample code?  Also try checking the Message property of the Exception.  Hopefully that will give us more information on why that call is failing.



          • Re: System.InvalidOperationException in Server.UpdateValues

            Please confirm if you're using 2.6.0 or 2.6.1. If you're using 2.6.1, if there're type conversion errors inside server.UpdateValues, they should be returned in AFErrors<AFValue> errors.


            Just for troubleshooting, check the following for each of AFValue being sent:


            - if the value is good, e.g. value.IsGood


            - the value type, e.g. value.GetType()


            - the point type, e.g. value.PIPoint.PointType


            - does the value contain annotation, e.g. value.Annotated, or value.AdditionalInfo


            Note that AFSDK does value type checking prior to sending to PIServer:


            - Value type can only be primitive (int, float, bool, etc), string, AFEnumerationValue, AFTime, DateTime, or byte[]. Otherwise, you'll get InvalidOperationException error.


            - Value type is restricted to Point type, e.g. if your Point type is blob or digital and your value type is long, you'll get InvalidOperationException error.


            - For simple Annotation, the type is restricted to primitive, string, byte[], DateTime, and AFTime. Otherwise, you'll get InvalidOperationException error.

              • Re: System.InvalidOperationException in Server.UpdateValues

                Value.IsGood : all true


                Value.GetType() : an Object which name is "AFValue" is returned. No value type in the sub field. (Something wrong here)


                PointType : all OK (digital)


                Value.Annotated : all false


                Value. AdditionalInfo : all null


                The GetType returns the Object itself and wouldn't be comparable with the PointType. The Object doesn't have a field which seems to be related to type. The PointType is Digital which I was expecting. The first tag is digital and it returns an error as soon as the program is run. The exception message is still the same. "Collection was modified; enumeration may not execute"


                Location: System.Collections.Generic.List`1.Enumerator.MoveNextRare()\r\n  


                Location: OSIsoft.AF.PI.PIServer.ConvertAFValuesToMDAEvents(IList`1 values, AFUpdateOption option, AFErrors`1& errors, IList`1& eventValues)\r\n  


                Location: OSIsoft.AF.PI.PIServer.UpdateValues(IList`1 values, AFUpdateOption option, AFBufferOption bufferOption)\r\n  


                Location: TcnetMultiLoader.MainForm.DoWork_Writing()


                The programmer has written a program previously and that one didn't have any problem although just now he checked the AFValue checklist above and still it was the same.