- Home /
C#.How to Deserialize?
I want to send something to server.This calss can running for .NET,but error
running for mono and Unity.Please give me some advice,Thanks。
public static System.Object YuanDeserialize(byte[] buffer)
{
System.Object obj = new System.Object();
using (MemoryStream ms = new MemoryStream())
{
IFormatter bf = new BinaryFormatter();
bf.Binder = new YuanBinder();
ms.Write(buffer, 0, buffer.Length);
ms.Position = 0;
obj = bf.Deserialize(ms);
}
return obj;
}
I let new class inherited Dictionary,is serializable.But another problem came out。
Answer by whydoidoit · Dec 29, 2012 at 04:24 PM
Your problem is a mismatch between versions of the .NET libraries between the server and the client. You could try my Unity Serializer which attempts to resolve type differences to compatible types on client and server.
That said, the generic keys might cause it to try and store the fully qualified types which will not be available.
Thank you for your answer。I let new class inherited Dictionary,is serializable.But another problem came out。
Answer by MarkFinn · Dec 29, 2012 at 03:37 PM
The class you are serializing contains a Dictionary object (from System.Collections.Generic). These are (I believe) not serializable.
Serializable classes can only contain serializable elements.
Ignore this one. I was just about as factually incorrect as it is possible to be without triggering a singularity.
Dictionaries are serializable, the problem here is the .NET version mismatch between server and client.
Hrm. I stand completely corrected. Sorry. I should not try to answer technical questions in the wee small hours of the morning. $$anonymous$$y bad.
Thank you for your answer。I let new class inherited Dictionary,is serializable.But another problem came out。
Your answer
![](https://koobas.hobune.stream/wayback/20220613090056im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers
i want to get all facebook user photos 0 Answers