AlistairFrith

Attribute.GetValue() returns "Specified cast is invalid". Why is this?

Discussion created by AlistairFrith on Mar 10, 2014
Latest reply on May 30, 2014 by Gregor

We have a project that collects the current values for a number of attributes of an element. These are all PI-Point attributes. On our development system, these values are all numeric and everything is lovely. But on the customer's site (on which we cannot run a debugger), the application displays "The specified cast is invalid" for all these PIPoint attributes. If I look at them in PI System explorer, they all have good values. Here is the (rather ugly) code:

 
double testDouble;
bool canParseDouble = double.TryParse(subRootItem.GetValue().ToString(), out testDouble);

subAttr.SubAttributes.Add
( 
    (subRootItem.Name != null)  ? subRootItem.Name : "N/A", 
    new AbstractedAFAttribute()
        {
            Name = (subRootItem.Name != null) ? subRootItem.Name : "N/A",

            Value = ( (canParseDouble)
                        ? String.Format("{0:0.00}", Convert.ToDouble(subRootItem.GetValue().ToString())) 
                        : 
"Not numeric: " + subRootItem.GetValue().ToString())
                    + ( (subRootItem.DefaultUOM != null && subRootItem.DefaultUOM.Abbreviation != null && canParseDouble)
                        ? subRootItem.DefaultUOM.Abbreviation.ToString() 
                        : "")
                    + "    " 
                    + "(" + (subRootItem.GetValue().Timestamp != null ? subRootItem.GetValue().Timestamp.ToString() : "No Timestamp available") + ")",

            PITag = (subRootItem.DataReference != null) ? subRootItem.DataReference.ToString() : "N/A",
        }
);

The red-highlighted bit is what we get at the customer site and the resultant text is "Not numeric: Specified cast is not valid" . subRootItem is an AFAttribute object.

 

Any ideas?

 

--- Alistair.

Outcomes