Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2004

Tip: Looking for answers? Try searching our database.

SerializationException during Deserialization of a class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob Walker - 20 May 2004 07:06 GMT
I am serializing the following struct

public struct Tan

    int x
    int y

using the following code

BinaryFormatter formatter = new BinaryFormatter()
MemoryStream mStream = new MemoryStream()
formatter.Serialize(mStream, tank)

and sending this to a UdpClient on a different machine using this code

IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("xxx.xxx.xxx.xxx"), 11000)
UdpClient client = new UdpClient()
client.Send(mStream.GetBuffer(), (int)mStream.Length, remoteEP)

Now then, my client is receiving the packet via the following cod
IPEndPoint localEP = new IPEndPoint(IPAddress.Parse("xxx.xxx.xxx.xxx"), 11000)
UdpClient client = new UdpClient(localEP)
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 11000)

BinaryFormatter formatter = new BinaryFormatter()
MemoryStream mStream = new MemoryStream()
byte[] message = client.Receive(ref remoteEP)
mStream.Write(message, 0, message.Length)
mStream.Position = 0

At this point, I compare the mStream that I sent to the mStream that arrived (breakpoints) and I see that they are in fact the same size, have the same bytes writting to them, etc. - they look absultely correct.  However, the following command causes the error in question

Tank tank = (Tank)formatter.Deserialize(mStream)

//The Tank structure is declared both on the server and the client and they look the exact same, etc . .

I get the following error
System.Runtime.Serialization.SerializationException: Cannot find the assembly MyClient, Version=1.0.1600.39535, Culture=neutral, PublicKeyToken=null
  at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly(
  at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Binar
  etc.... etc.... etc...

MyClient is the assembly that SENT the original packet.  Why is the MyServer assembly (the packet receiver) throwing an error about the sending machines assembly?  I'm only trying to serialize a class and I'm baffled as to why assembly information has anything to do with deserializing it - but then again, I'm new to Serialization :

I've been struggling with this now for 3 days and my deadline is tommorrow.  I sure hope I can find an answer soon :

Thanks in advance for any replies
Kurbangaliev Denis V. - 20 May 2004 07:31 GMT
You need...

[Serializable]

public struct Tank
{
    int x;
    int y;
}

> I am serializing the following struct:
>
[quoted text clipped - 28 lines]
>
> At this point, I compare the mStream that I sent to the mStream that arrived (breakpoints) and I see that they are in fact the same size, have
the same bytes writting to them, etc. - they look absultely correct.
However, the following command causes the error in question:

> Tank tank = (Tank)formatter.Deserialize(mStream);
>
> //The Tank structure is declared both on the server and the client and they look the exact same, etc . . .
>
> I get the following error:
> System.Runtime.Serialization.SerializationException: Cannot find the assembly MyClient, Version=1.0.1600.39535, Culture=neutral,
PublicKeyToken=null.
>    at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembl
y()
>    at
System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Binary
>    etc.... etc.... etc....
>
> MyClient is the assembly that SENT the original packet.  Why is the MyServer assembly (the packet receiver) throwing an error about the sending
machines assembly?  I'm only trying to serialize a class and I'm baffled as
to why assembly information has anything to do with deserializing it - but
then again, I'm new to Serialization :)

> I've been struggling with this now for 3 days and my deadline is tommorrow.  I sure hope I can find an answer soon :(
>
> Thanks in advance for any replies.
>
> Rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.