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. Serialization

Serialization

Scheduled Pinned Locked Moved C#
helpquestionjsontutorial
3 Posts 2 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
    dwebster
    wrote on last edited by
    #1

    I am having a problem with serialization and deserialization of classes using the BinaryFormatter. I have two different programs and I want to serialize a class in the Test1 program and transfer it using sockets to the Test2 program and deserialize it into a replica class. When I attempt to deserialize in the Test2 program, I get the following System.IO.FileNotFoundException: File or assembly name Test1, or one of its dependencies, was not found. Here is an example of how I am serializing: SomeClass sc = new SomeClass(); sc.var1 = 12; sc.var2 = m_strTemp; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms,(object)sc); After receiving buffer of serialized data, here is an example of how I am deserializing: BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(buffer,0,nBytesRead,true,true); SomeClass sc = (SomeClass)bf.Deserialize(ms); What am I doing wrong? How can I deserialize in an entirely different process, in a different program, on a different machine and not receive this error? Thanks! Donald

    J 1 Reply Last reply
    0
    • D dwebster

      I am having a problem with serialization and deserialization of classes using the BinaryFormatter. I have two different programs and I want to serialize a class in the Test1 program and transfer it using sockets to the Test2 program and deserialize it into a replica class. When I attempt to deserialize in the Test2 program, I get the following System.IO.FileNotFoundException: File or assembly name Test1, or one of its dependencies, was not found. Here is an example of how I am serializing: SomeClass sc = new SomeClass(); sc.var1 = 12; sc.var2 = m_strTemp; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms,(object)sc); After receiving buffer of serialized data, here is an example of how I am deserializing: BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(buffer,0,nBytesRead,true,true); SomeClass sc = (SomeClass)bf.Deserialize(ms); What am I doing wrong? How can I deserialize in an entirely different process, in a different program, on a different machine and not receive this error? Thanks! Donald

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Classes in .NET are assembly specific, so if you and I both create a class called Foo with the exact same code but you have yours in the assembly donald.dll but mine is in the assembly james.dll they are considered incompatible types if the contents of the two assemblies differ. The way to get around it is to place the classes that will be shared between the two applications into a separate assembly (class library to use VS.NET terms). Then the client program and the server program both reference this assembly. HTH, James "And we are all men; apart from the females." - Colin Davies

      D 1 Reply Last reply
      0
      • J James T Johnson

        Classes in .NET are assembly specific, so if you and I both create a class called Foo with the exact same code but you have yours in the assembly donald.dll but mine is in the assembly james.dll they are considered incompatible types if the contents of the two assemblies differ. The way to get around it is to place the classes that will be shared between the two applications into a separate assembly (class library to use VS.NET terms). Then the client program and the server program both reference this assembly. HTH, James "And we are all men; apart from the females." - Colin Davies

        D Offline
        D Offline
        dwebster
        wrote on last edited by
        #3

        That works very well... thank you very much!

        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