Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# newbie serialization problem

c# newbie serialization problem

Scheduled Pinned Locked Moved C#
csharpsysadminhelpdotnetwcf
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dorutzu
    wrote on last edited by
    #1

    Hi, I'm just starting to learn C#(and I like it) and .NET Framework, and I stared with this: I want to make a chat application. Basically, I have a server and a client, connected via sockets (all works just fine). Now, I would like the client to send some info to the server -> a serialized object (because there are many types of values in this object). The problem is that the server and the client are not the same application, and thus, deserialization doesn't work (or at least, I couldn't make it work...maybe you can help here). This is the code I use for serialization: MemoryStream ms = new MemoryStream(); StreamingContext stmCtx = new StreamingContext(StreamingContextStates.CrossMachine | StreamingContextStates.Persistence); BinaryFormatter bf = new BinaryFormatter(null, stmCtx); bf.AssemblyFormat = FormatterAssemblyStyle.Simple; bf.TypeFormat = FormatterTypeStyle.TypesWhenNeeded; bf.Serialize(ms, negociate_struct); ...and then I send ms over the network. Now, serialization is basicaly ok (because if I deserialize here ms, is works fine), but on the server I got this IOException : "File or assembly name RCClient, or one of its dependencies, was not found." RCClient is my client application name. I also saved my stream to a file, and got something like: "  ˙˙˙˙  RCClient %NegociationStructures.NegociateStruct SenderTypePacketNo NPResponse   xxx " It's obvious my server application doesn't know who RCClient is. I figure the problem is either with setting the BinaryFormatter, or I use the wrong tool for the job. Also, I can't use SOAP serialization, because I noticed that the stream is much larger, and I need as much speed as possible (this should eventually develop into a video chat & stuff). I hope I made my problem clear, and I would appreciate any help or hint. Thank you in advance, Doru K.

    J H 2 Replies Last reply
    0
    • D dorutzu

      Hi, I'm just starting to learn C#(and I like it) and .NET Framework, and I stared with this: I want to make a chat application. Basically, I have a server and a client, connected via sockets (all works just fine). Now, I would like the client to send some info to the server -> a serialized object (because there are many types of values in this object). The problem is that the server and the client are not the same application, and thus, deserialization doesn't work (or at least, I couldn't make it work...maybe you can help here). This is the code I use for serialization: MemoryStream ms = new MemoryStream(); StreamingContext stmCtx = new StreamingContext(StreamingContextStates.CrossMachine | StreamingContextStates.Persistence); BinaryFormatter bf = new BinaryFormatter(null, stmCtx); bf.AssemblyFormat = FormatterAssemblyStyle.Simple; bf.TypeFormat = FormatterTypeStyle.TypesWhenNeeded; bf.Serialize(ms, negociate_struct); ...and then I send ms over the network. Now, serialization is basicaly ok (because if I deserialize here ms, is works fine), but on the server I got this IOException : "File or assembly name RCClient, or one of its dependencies, was not found." RCClient is my client application name. I also saved my stream to a file, and got something like: "  ˙˙˙˙  RCClient %NegociationStructures.NegociateStruct SenderTypePacketNo NPResponse   xxx " It's obvious my server application doesn't know who RCClient is. I figure the problem is either with setting the BinaryFormatter, or I use the wrong tool for the job. Also, I can't use SOAP serialization, because I noticed that the stream is much larger, and I need as much speed as possible (this should eventually develop into a video chat & stuff). I hope I made my problem clear, and I would appreciate any help or hint. Thank you in advance, Doru K.

      J Offline
      J Offline
      John Fisher
      wrote on last edited by
      #2

      dorutzu wrote: "File or assembly name RCClient, or one of its dependencies, was not found." That indicates that your server application doesn't know how to find the type information for the object that your client sent over. To fix this, move all shared classes into a "Class Library" (dll) that both the client and the server applications use. John
      "You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.

      1 Reply Last reply
      0
      • D dorutzu

        Hi, I'm just starting to learn C#(and I like it) and .NET Framework, and I stared with this: I want to make a chat application. Basically, I have a server and a client, connected via sockets (all works just fine). Now, I would like the client to send some info to the server -> a serialized object (because there are many types of values in this object). The problem is that the server and the client are not the same application, and thus, deserialization doesn't work (or at least, I couldn't make it work...maybe you can help here). This is the code I use for serialization: MemoryStream ms = new MemoryStream(); StreamingContext stmCtx = new StreamingContext(StreamingContextStates.CrossMachine | StreamingContextStates.Persistence); BinaryFormatter bf = new BinaryFormatter(null, stmCtx); bf.AssemblyFormat = FormatterAssemblyStyle.Simple; bf.TypeFormat = FormatterTypeStyle.TypesWhenNeeded; bf.Serialize(ms, negociate_struct); ...and then I send ms over the network. Now, serialization is basicaly ok (because if I deserialize here ms, is works fine), but on the server I got this IOException : "File or assembly name RCClient, or one of its dependencies, was not found." RCClient is my client application name. I also saved my stream to a file, and got something like: "  ˙˙˙˙  RCClient %NegociationStructures.NegociateStruct SenderTypePacketNo NPResponse   xxx " It's obvious my server application doesn't know who RCClient is. I figure the problem is either with setting the BinaryFormatter, or I use the wrong tool for the job. Also, I can't use SOAP serialization, because I noticed that the stream is much larger, and I need as much speed as possible (this should eventually develop into a video chat & stuff). I hope I made my problem clear, and I would appreciate any help or hint. Thank you in advance, Doru K.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        You should also read How the Runtime Locates Assemblies[^] in the .NET Framework SDK. Serialization does pack-up your object graph (your RCClient in this case) but it needs to deserialize it back into an instance of that class so it's still required on both ends. As the previous post mentioned, put all shared classes in an assembly that both the server and client can access and make sure it can be found. Finally, you might want to look at .NET Remoting. It serializes data in an extensible manner (i.e., you can specify whether or not to use the binary, SOAP, or a custom formatter, and whether or not to use the HTTP, TCP, or custom transport channel) and marshals it across the wire. This also opens your application up for a good AOP (aspect-oriented programming) model so that you can intercept methods and log them, encrypt them transparently to the method calls in your program, etc. Basically, you're already doing the very basics of what Remoting is, but you'll find that Remoting is a proven, extensible, and tested implementation. Read Accessing Objects in Other Application Domains using .NET Remoting[^] also in the .NET Framework SDK for more information.

        Microsoft MVP, Visual C# My Articles

        D 1 Reply Last reply
        0
        • H Heath Stewart

          You should also read How the Runtime Locates Assemblies[^] in the .NET Framework SDK. Serialization does pack-up your object graph (your RCClient in this case) but it needs to deserialize it back into an instance of that class so it's still required on both ends. As the previous post mentioned, put all shared classes in an assembly that both the server and client can access and make sure it can be found. Finally, you might want to look at .NET Remoting. It serializes data in an extensible manner (i.e., you can specify whether or not to use the binary, SOAP, or a custom formatter, and whether or not to use the HTTP, TCP, or custom transport channel) and marshals it across the wire. This also opens your application up for a good AOP (aspect-oriented programming) model so that you can intercept methods and log them, encrypt them transparently to the method calls in your program, etc. Basically, you're already doing the very basics of what Remoting is, but you'll find that Remoting is a proven, extensible, and tested implementation. Read Accessing Objects in Other Application Domains using .NET Remoting[^] also in the .NET Framework SDK for more information.

          Microsoft MVP, Visual C# My Articles

          D Offline
          D Offline
          dorutzu
          wrote on last edited by
          #4

          Thank you very much for your answers. I took the easy way, and just bundeled everything in a .dll for both applications to use it...and it works just great! And it was so easy... Thanks again! Keep in touch, Doru

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups