1

I have a problem:

    protected Test(SerializationInfo info, StreamingContext context)
    {         
        sx = info.GetUInt16("sizex");
        sy = info.GetUInt16("sizey");
        sz = info.GetUInt16("sizez");
        ushort[] tab = new ushort[sx * sy * sz];
        tab = info.GetValue("data", System.UInt16[sx * sy * sz]);
        Console.WriteLine("Deserializing constructor");
    }
    [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        Console.WriteLine("Serializing...");
        info.AddValue("sizex", sx);
        info.AddValue("sizey", sy);
        info.AddValue("sizez", sz);           
        info.AddValue("data", tab);
    }

I get a compile-time error: 'ushort' is a 'type', which is not valid in the given context. What should I change ?

1
  • how you are using sx,sy,sz in "GetObjectData" and they are local to the function "Test"? Commented Dec 22, 2011 at 22:16

2 Answers 2

3

info.GetValue expects a type, so you do not include a size for the array and you wrap it with a typeof. Also, ushort[] tab = new ushort[sx * sy * sz]; is unnecessary.

ushort[] tab = (ushort[])info.GetValue("data", typeof(ushort[]));
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

    protected Test(SerializationInfo info, StreamingContext context)
    {         
        sx = info.GetUInt16("sizex");
        sy = info.GetUInt16("sizey");
        sz = info.GetUInt16("sizez");
        ushort[] tab = new ushort[sx * sy * sz];
        tab = (ushort[])info.GetValue("data", tab.GetType());
        Console.WriteLine("Deserializing constructor");
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.