0

I'm having some trouble figuring out how to deserialize a binary file. I mostly can't figure out how to use the second argument of SerializationInfo.GetValue(); - if I just put a type keyword there, it's invalid, and if I use the TypeCode, it's invalid as well. This is my current attempt (obviously it doesn't build).

        protected GroupMgr(SerializationInfo info, StreamingContext context) {
        Groups = (Dictionary<int, Group>) info.GetValue("Groups", (Type) TypeCode.Object);
        Linker = (Dictionary<int, int>) info.GetValue("Linker", (Type) TypeCode.Object );
        }

3 Answers 3

3

The second argument in SerializationInfo.GetValue is the object type:

        protected GroupMgr(SerializationInfo info, StreamingContext context) {
            Groups = (Dictionary<int, Group>) info.GetValue("Groups", typeof(Dictionary<int, Group>));
            Linker = (Dictionary<int, int>) info.GetValue("Linker", typeof(Dictionary<int, int>));
            }
Sign up to request clarification or add additional context in comments.

Comments

0
typeof(object)

or

instance.GetType()

where instance is an object. Of course, replace by the actual types in your case.

Comments

0

Instantiate temporary variables:

Dictionary<int, Group> tmpDict = new Dictionary<int, Group>();
Dictionary<int, int> tmpLinker = new Dictionary<int, int>();

then in your lines below:

Groups = (Dictionary<int, Group>) info.GetValue("Groups", tmpDict.GetType());
Linker = (Dictionary<int, int>) info.GetValue("Linker", tmpLinker.GetType());

Hope this helps, Best regards, Tom.

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.