У меня возникла проблема с сериализацией/десериализацией в приложениях 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);
на Otherside
TcpClient client = server.AcceptTcpClient();
NetworkStream stream = client.GetStream();
BinaryFormatter b = new BinaryFormatter();
SerializerObject o= (SerializerObject)b.Deserialize(stream);
Эта команда даст мне отл eption Первый шанс исключение типа 'System.Runtime.Serialization.SerializationException' произошло в mscorlib.dll
и если я напечатать e.message = "невозможно найти l'сборочный«ProgettoServerV2, Version = 1.0.0.0, Культура = нейтральная, PublicKeyToken = null '. "
e.stacktrace = в System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() \ г \ п в System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType (BinaryAssemblyInfo AssemblyInfo, имя String) \ 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 , SizedArray assemIdToAssemblyTable) \ r \ n в System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.ReadObjectWithMapTyped (BinaryObjectWithMapTyped record) \ r \ n в System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.ReadObjectWithMapTyped (BinaryHeaderEnum binaryHeaderEnum) \ r \ n в System.Runtime.Serialization.Formatters.Binary .__ BinaryParser.Run() \ r \ n в System.Runtime.Seri alization.Formatters.Binary.ObjectReader.Deserialize (обработчик HeaderHandler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, метод IMethodCallMessageCallMessage) \ r \ n в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (Stream serializationStream, обработчик HeaderHandler, Boolean fCheck, Boolean isCrossAppDomain, метод IMethodCallMessageCallMessage) \ r \ n в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (Stream serializationStream) \ r \ n в GraficaClient.GestoreClipboard.gestioneClipboard() в c: \ Users \ pietro \ Desktop \ GraficaClient \ GraficaClient \ GestoreClipboard.cs: riga 91
В настоящее время я использую VisualStudio 2013. Как это можно решить.