When byte Transfer is changed to an object today, an error is always reported. Later, the cause is that the stream index is set to the starting position, because the index is moved to the starting position after serialization.
The end of the stream, so an error is reported.CodeAs follows:
Public Static T deserializer <t> ( Byte [] Buffer, Int Length)
{
Try
{
String Mtextreceived = encoding. utf8. Getstring (Buffer, 0 , Length );
Socketdatapack SDP = Getsocketdatapackfromstring (Mtextreceived );
// The memorystream object provides a method to create a stream without Io.
memorystream stream = New memorystream ();
binaryformatter formatter = New binaryformatter ();
formatter. serialize (stream, SDP);
// Set the stream index to the start position.
Stream. Position =0;
// Make sure that the writer is updated to stream;
Stream. Flush ();
Object OBJ = formatter. Deserialize (Stream );
If (OBJ = Null )
{
Return Default (T );
}
Return (T) OBJ;
}< br> catch (exception ex)
{< br> throw ex;
}< BR >}