2014-12-13 79 views
-1

我在套接字之间进行通信的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. 我该如何解决它。

回答

0

确保程序可以加载缺少的程序集。错误信息中很难理解什么?见了我引用你唯一相关的片inforamtion在你的页面很长的帖子:

e.message =“无法找到L'集“ProgettoServerV2,版本= 1.0.0.0,文化=中立, 公钥=空”“。

确保此程序集可用并且反序列化可以工作。

相关问题