Click here to Skip to main content
15,886,362 members
Home / Discussions / C#
   

C#

 
GeneralRe: Backslashes and forward slashes Pin
OriginalGriff4-Apr-10 21:38
mveOriginalGriff4-Apr-10 21:38 
GeneralRe: Backslashes and forward slashes Pin
Ravi Bhavnani4-Apr-10 8:15
professionalRavi Bhavnani4-Apr-10 8:15 
AnswerRe: Backslashes and forward slashes Pin
Dave Kreskowiak4-Apr-10 7:49
mveDave Kreskowiak4-Apr-10 7:49 
GeneralRe: Backslashes and forward slashes Pin
Darrall4-Apr-10 8:05
Darrall4-Apr-10 8:05 
GeneralRe: Backslashes and forward slashes Pin
PIEBALDconsult4-Apr-10 13:40
mvePIEBALDconsult4-Apr-10 13:40 
QuestionAdding items to ListView groups Pin
teknolog1234-Apr-10 4:09
teknolog1234-Apr-10 4:09 
AnswerRe: Adding items to ListView groups Pin
Luc Pattyn4-Apr-10 4:12
sitebuilderLuc Pattyn4-Apr-10 4:12 
QuestionSerializationException was unhandled Message="Unable to find assembly... " problem Pin
barak drechsler4-Apr-10 3:37
barak drechsler4-Apr-10 3:37 
Hello,
I am writing a messenger like client server application for a school project.
My client and server are communicating trough tcp protocol via the the .net sockets.
It all worked fine untill I tried to transfer complex data from the server to the client,like a custom classes I made.
To transfer this data I have decided to use Serialization and turn the objects to bytes,than send the bytes to the client via the the sockets SendTo method.
I did manage to send the object,but when I try to deserialize the bytes back to an object on the server side , I get this exception
System.Runtime.Serialization.SerializationException was unhandled
  Message="Unable to find assembly 'SmallTalkServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
  Source="mscorlib"

I googled around for a few hours and learned that the source of the prroblem is that since the object was serialized on the server side application that have X assembles,it can't be deserialized on the client server which other assembles.
I tried to use the proprtey
bf.AssemblyFormat = FormatterAssemblyStyle.Simple;

But it didn't help,also from my searching I learned that there is a bug with the proprtey (I am using 3.5 framework s1)
I tried to change to soap foramtter and I soon learned that soap foramatter can not serialize generic types and thus he is help less for me.
I am really not sure how to solve this problem,please help me,
Thanks in advance!

btw this is my Serializer class which I have the same on both of the app.
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Formatters;


namespace SmallTalkServer
{
    public static class Serializer
    {

        public static void SerializeObject(string filename, BuddyList buddyList)
        {
            Stream stream = File.Open(filename, FileMode.Create);
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            bFormatter.Serialize(stream, buddyList);
            stream.Close();
        }

        public static BuddyList DeSerializeObject(string filename)
        {
            BuddyList buddylist;
            Stream stream = File.Open(filename, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            buddylist = (BuddyList)bFormatter.Deserialize(stream);
            stream.Close();
            return buddylist;

        }
        public static BuddyList DeSerializeObject(byte[] arrBytes)
        {
            MemoryStream memStream = new MemoryStream();
            memStream.Write(arrBytes, 0, arrBytes.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            BuddyList buddylist;
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
            buddylist = (BuddyList)bFormatter.Deserialize(memStream);
            memStream.Close();
            return buddylist;

        }

        public static byte[] ObjectToByteArray(object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter bf = new BinaryFormatter();
            bf.AssemblyFormat = FormatterAssemblyStyle.Simple;
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            return ms.ToArray();

        }

        public static object ByteArrayToObject(byte[] arrBytes)
        {
            MemoryStream memStream = new MemoryStream();
            BinaryFormatter binForm = new BinaryFormatter();
            binForm.AssemblyFormat = FormatterAssemblyStyle.Simple;
            memStream.Write(arrBytes, 0, arrBytes.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            object obj = (object)binForm.Deserialize(memStream);
            return obj;
        }
    }
}

AnswerRe: SerializationException was unhandled Message="Unable to find assembly... " problem Pin
Nicholas Butler4-Apr-10 6:23
sitebuilderNicholas Butler4-Apr-10 6:23 
GeneralRe: SerializationException was unhandled Message="Unable to find assembly... " problem Pin
barak drechsler4-Apr-10 7:39
barak drechsler4-Apr-10 7:39 
GeneralRe: SerializationException was unhandled Message="Unable to find assembly... " problem Pin
Nicholas Butler4-Apr-10 8:01
sitebuilderNicholas Butler4-Apr-10 8:01 
GeneralRe: SerializationException was unhandled Message="Unable to find assembly... " problem Pin
barak drechsler4-Apr-10 8:45
barak drechsler4-Apr-10 8:45 
QuestionUnnecessory process - please wait while windows configures Pin
Milind Panchal4-Apr-10 2:18
Milind Panchal4-Apr-10 2:18 
QuestionHide subproperty in PropertyGrid Pin
viciouskinid3-Apr-10 23:39
viciouskinid3-Apr-10 23:39 
AnswerRe: Hide subproperty in PropertyGrid Pin
OriginalGriff4-Apr-10 1:27
mveOriginalGriff4-Apr-10 1:27 
GeneralRe: Hide subproperty in PropertyGrid Pin
viciouskinid4-Apr-10 16:29
viciouskinid4-Apr-10 16:29 
QuestionForwarding received SMS from the phone to output Pin
Kujtim Hyseni3-Apr-10 22:29
Kujtim Hyseni3-Apr-10 22:29 
QuestionHow can i find some Hardware information on run time ? Pin
Yanshof3-Apr-10 13:37
Yanshof3-Apr-10 13:37 
AnswerRe: How can i find some Hardware information on run time ? Pin
Eddy Vluggen3-Apr-10 14:28
professionalEddy Vluggen3-Apr-10 14:28 
GeneralRe: How can i find some Hardware information on run time ? Pin
Yanshof3-Apr-10 14:31
Yanshof3-Apr-10 14:31 
GeneralRe: How can i find some Hardware information on run time ? Pin
Eddy Vluggen3-Apr-10 14:37
professionalEddy Vluggen3-Apr-10 14:37 
AnswerRe: How can i find some Hardware information on run time ? Pin
Ravi Bhavnani3-Apr-10 14:42
professionalRavi Bhavnani3-Apr-10 14:42 
QuestionProduct key feature Pin
Alok Sharma ji3-Apr-10 3:12
Alok Sharma ji3-Apr-10 3:12 
AnswerRe: Product key feature Pin
xEvOx3-Apr-10 3:41
xEvOx3-Apr-10 3:41 
GeneralRe: Product key feature Pin
Alok Sharma ji3-Apr-10 3:47
Alok Sharma ji3-Apr-10 3:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.