AnsweredAssumed Answered

Why does PropertyInfo.GetValue() function return null for PropertyInfo AFContact?

Question asked by Noga on Jan 2, 2019
Latest reply on Jan 7, 2019 by Eugene Lee

I exported a database XML from a PI-AF server using the PI System Explorer tool (the server version: PI-AF-Services_2017-R2-Update-1),

and I use the following function to import the database to another PI-AF server (with the same version: PI-AF-Services_2017-R2-Update-1), after converting the xml to an object.


My function uses the Mono.Reflection.dll to retrieve values from that object.


the object “object ob “ sent to the function is my PISystem object I retrieved by querying  AFDatabase.PISystem .




bool GetProperty(object ob, string pName, ref object pValue, BindingFlags bFlags)



            Type obType = ob.GetType();           


            PropertyInfo pi = obType.GetProperty(pName, bFlags);


            if (null != pi)




                    if(pi.GetIndexParameters().Length == 0)

                        pValue = pi.GetValue(ob);

                    return true;


                catch (Exception e)


                    return false;




            Type bt = obType.BaseType;

            if (null == bt)           

                return false;



            return GetProperty(ob, bt, pName, ref pValue, bFlags);





The problem I encounter is as follows:

When I call that GetProperty() function to find the ‘AFDeliveryFormat’ or the 'AFNotificationContactTemplate' objects from my PISystem object, like this:


GetProperty(MyPISystemObj, “AFDeliveryFormat”, objRef, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)


The function works fine and returns the requested pValue.

It also works fine for other xml properties.


But, When I call that function to find the ‘AFContact’ object like this:

GetProperty(MyPISystemObj, “CurrentContact”, objRef, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)


The line:  pValue = pi.GetValue(ob);   returns me a Null (pValue == null).


When debugging the code I can see that  the value returned from the call:

PropertyInfo pi = obType.GetProperty(pName, bFlags);

returns the expected: OSIsoft.AF.AFContact property.


I have noticed that the PropertyInfo.CanWrite property is set to true on the OSIsoft.AF.AFContact property returned, and false for those PropertyInfo that do not return null,

Can that be part of the issue?



I cannot understand what I am doing wrong. What am I missing?


I will be grateful for any ideas and solutions!