我在套接字之間進行通信的Wpf應用程序中的序列化/反序列化有問題。 在細節: 在這兩個應用程序 我已經實現了ISerializable的類:二進制序列化C#:反序列化方法給我例外
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace GraficaClient
{
[Serializable()] //Set this attribute to all the classes that want to serialize
class SerializerObject : ISerializable
{
public String type;
public String txt;
/*public String rft;
public Byte[] audio;
public Byte[] img;
*/
public SerializerObject()
{
}
//Deserialization constructor.
public SerializerObject(SerializationInfo info, StreamingContext ctxt)
{
//Get the values from info and assign them to the appropriate properties
type = (String)info.GetValue("type", typeof(String));
txt= (String)info.GetValue("txt", typeof(String));
/* rft = (String)info.GetValue("rft", typeof(String));
audio = (Byte[])info.GetValue("audio", typeof(Byte[]));
img = (Byte[])info.GetValue("img", typeof(Byte[]));*/
}
//Serialization function.
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("type", type);
info.AddValue("txt", txt);
/*info.AddValue("rft", rft);
info.AddValue("audio",audio);
info.AddValue("img", img);*/
}
}
}
在我的應用程序之一,我把信息內(在這種情況下,只有拖字符串) 和流序列化
TcpClient c = new TcpClient();
SerializerObject o = new SerializerObject();
o.type="t";
o.text="hello";
c.Connect(ip,port);
NetworkStream stream = c.GetStream();
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, o);
在阿瑟賽德
TcpClient client = server.AcceptTcpClient();
NetworkStream stream = client.GetStream();
BinaryFormatter b = new BinaryFormatter();
SerializerObject o= (SerializerObject)b.Deserialize(stream);
該指令
給我一個EXC主器件接收 型「System.Runtime.Serialization.SerializationException」的第一次機會異常出現在mscorlib.dll
,如果我打印e.message =「無法找到L'集「ProgettoServerV2,版本= 1.0.0.0, Culture = neutral,PublicKeyToken = null'。「
e.stacktrace =在System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly(個)\ r \ n的System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo集信息,字符串名稱)\ r \ n在System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName,String [] memberNames,BinaryTypeEnum [] binaryTypeEnumA,Object [] typeInformationA,Int32 [] memberAssemIds,ObjectReader objectReader,Int32 objectId,BinaryAssemblyInfo assemblyInfo System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)\ System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)\ r \ n中的SizedArray assemIdToAssemblyTable)\ r \ n \ r \ System.Runtime.Serialization.Formatters.Binary中的\ n BinaryParser.Run()\ r \ n System.Runtime.Seri System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream,HeaderHandler handler)中的alization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler處理函數,__BinaryParser serParser,布爾fCheck,布爾isCrossAppDomain,IMethodCallMessage methodCallMessage)\ r \布爾fCheck,布爾isCrossAppDomain,IMethodCallMessage methodCallMessage)\ r \ n在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)\ r \ n在GraficaClient.GestoreClipboard.gestioneClipboard()在c:\用戶\ pietro \ Desktop \ GraficaClient \ GraficaClient \ GestoreClipboard.cs:riga 91
當前我正在使用VisualStudio 2013. 我該如何解決它。