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. Problem during deserialization

Problem during deserialization

Scheduled Pinned Locked Moved C#
7 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.
  • L Offline
    L Offline
    lnmca
    wrote on last edited by
    #1

    Hi All, I am unable to deserialize the byte array to the object of structure on another machine,when i send it through TCP/IP by socket then there is no problem in serialization.,but problem occurs at the other side during deserialization. It shows the error something like "unable to find assembly....." I am using the following code.... private byte[] ObjectToByteArray(Object obj) { if (obj == null) return null; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, obj); return ms.ToArray(); } // Convert a byte array to an Object private Object ByteArrayToObject(byte[] arrBytes) { MemoryStream memStream = new MemoryStream(arrBytes); BinaryFormatter binForm = new BinaryFormatter(); memStream.Position = 0; //memStream.Write(arrBytes, 0, arrBytes.Length); // memStream.Seek(0, SeekOrigin.Begin); Object obj = (Object)binForm.Deserialize(memStream); return obj; } Please help,it is urgent.... Regards Lalit Narayan

    R 1 Reply Last reply
    0
    • L lnmca

      Hi All, I am unable to deserialize the byte array to the object of structure on another machine,when i send it through TCP/IP by socket then there is no problem in serialization.,but problem occurs at the other side during deserialization. It shows the error something like "unable to find assembly....." I am using the following code.... private byte[] ObjectToByteArray(Object obj) { if (obj == null) return null; BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, obj); return ms.ToArray(); } // Convert a byte array to an Object private Object ByteArrayToObject(byte[] arrBytes) { MemoryStream memStream = new MemoryStream(arrBytes); BinaryFormatter binForm = new BinaryFormatter(); memStream.Position = 0; //memStream.Write(arrBytes, 0, arrBytes.Length); // memStream.Seek(0, SeekOrigin.Begin); Object obj = (Object)binForm.Deserialize(memStream); return obj; } Please help,it is urgent.... Regards Lalit Narayan

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      That's telling you that it needs to know about the type (defined in an assembly you don't have loaded) in order to deserialise it. Make sure its in your project's references on the deserialisation side.

      Regards, Rob Philpott.

      L 1 Reply Last reply
      0
      • R Rob Philpott

        That's telling you that it needs to know about the type (defined in an assembly you don't have loaded) in order to deserialise it. Make sure its in your project's references on the deserialisation side.

        Regards, Rob Philpott.

        L Offline
        L Offline
        lnmca
        wrote on last edited by
        #3

        Hi Rob, thanks for reply, but i have not attached the assembly at my side because i have to only read the data that is coming through TCP channel from the controller. Please reply... Regards, Lalit Narayan

        R 1 Reply Last reply
        0
        • L lnmca

          Hi Rob, thanks for reply, but i have not attached the assembly at my side because i have to only read the data that is coming through TCP channel from the controller. Please reply... Regards, Lalit Narayan

          R Offline
          R Offline
          Rob Philpott
          wrote on last edited by
          #4

          What you have there is a method to convert an object to a byte array, and a method to convert a byte array to an object. What you're transmitting is the member data of the object. All the methods and code for it isn't sent - that's defined in an assembly. You need to make sure that for any type which is sent this way, the assembly which contains it is on both client and server. Find out which assembly the type you are serialising is in. Then make sure that assembly is referenced in the project dependencies of the deserialising project.

          Regards, Rob Philpott.

          L 1 Reply Last reply
          0
          • R Rob Philpott

            What you have there is a method to convert an object to a byte array, and a method to convert a byte array to an object. What you're transmitting is the member data of the object. All the methods and code for it isn't sent - that's defined in an assembly. You need to make sure that for any type which is sent this way, the assembly which contains it is on both client and server. Find out which assembly the type you are serialising is in. Then make sure that assembly is referenced in the project dependencies of the deserialising project.

            Regards, Rob Philpott.

            L Offline
            L Offline
            lnmca
            wrote on last edited by
            #5

            Hi Rob, Thanks for ur reply.. Actually the problem is that we are communicating the DDC through windows service,on DDC side there is no .Net assembly but the embeded type of work over there(like C++ type). Now if when we receive the byte array from DDC then i have to convert it into object of my own created structure same as DDC side. But for testing purpose i am communicating between two computers that have .net application and windows service.But basically i have to set up communication between windows service and the DDC. So i do not want to attach the assembly..because there will no assembly on other side in real time. Please reply... Regards, Lalit Narayan

            R G 2 Replies Last reply
            0
            • L lnmca

              Hi Rob, Thanks for ur reply.. Actually the problem is that we are communicating the DDC through windows service,on DDC side there is no .Net assembly but the embeded type of work over there(like C++ type). Now if when we receive the byte array from DDC then i have to convert it into object of my own created structure same as DDC side. But for testing purpose i am communicating between two computers that have .net application and windows service.But basically i have to set up communication between windows service and the DDC. So i do not want to attach the assembly..because there will no assembly on other side in real time. Please reply... Regards, Lalit Narayan

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #6

              lnmca wrote:

              Now if when we receive the byte array from DDC then i have to convert it into object of my own created structure same as DDC side.

              That's not good enough. When you call serialize, it packages up the fully qualified type name - that includes namespace, type name and assembly. When deserialising on the other side it will use all these things to create the type prior to populating it. Just because you have a type with the same name .NET will not use that. I don't entirely understand what's you trying to do, but unless both sides are .NET you want to steer clear of Serialisation and just send the relevant fields one by one.

              Regards, Rob Philpott.

              1 Reply Last reply
              0
              • L lnmca

                Hi Rob, Thanks for ur reply.. Actually the problem is that we are communicating the DDC through windows service,on DDC side there is no .Net assembly but the embeded type of work over there(like C++ type). Now if when we receive the byte array from DDC then i have to convert it into object of my own created structure same as DDC side. But for testing purpose i am communicating between two computers that have .net application and windows service.But basically i have to set up communication between windows service and the DDC. So i do not want to attach the assembly..because there will no assembly on other side in real time. Please reply... Regards, Lalit Narayan

                G Offline
                G Offline
                Giorgi Dalakishvili
                wrote on last edited by
                #7

                If on the other end you have a different type but with same fields then this how to deserialize: Advanced Binary Serialization: Deserializing an Object Into a Different Type Than the One It was Serialized Into[^]

                Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

                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