Question

I am getting an object from a web service call and I am storing that in a hidden field by serializing the object. Then I am deserilizing the object and it is coming like the below screenshot :

enter image description here

My problem is when I am trying to access the below information by many ways, I an getting Invalid cast error OR System.InvalidCastException: Specified cast is not valid

decodedValues[0][2].Value
decodedValues[1][2].Value
decodedValues[2][2].Value

--etc

Any idea how can I get it in ASP.NET 1.1?

Was it helpful?

Solution

A simple method would do the trick:

public string[] GetValues(object[] decodedValues)
{
    string[] returnValues = new string[decodedValues.Length];

    for(int i=0; i<decodedValues.Length; i++)
    {
        returnValues[i] = ((XmlAttribute[])decodedValues[i])[2].Value;
    }

    return returnValues;
}

But remember: If the types from your screenshot don't match, you'll get your InvalidCastException.. So there is room for some improvement to check if the types match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top