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. Issue regarding Serialization [modified]

Issue regarding Serialization [modified]

Scheduled Pinned Locked Moved C#
sysadminjsonhelptutorialdiscussion
2 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.
  • F Offline
    F Offline
    free_soul424
    wrote on last edited by
    #1

    Hi, I am facing an issue in serialization. I have a class that implement ISerializable interface. Actually I want to make my object to travel on the network. If I don’t implemetn the ISerializable interfce and use the following code I can get the same functionality.

    public static Object GetSerializedObject (Object pObject)
    {
    try
    {
    BinaryFormatter objBinaryFormatter = new BinaryFormatter();
    MemoryStream objMemoryStream = new MemoryStream();
    objBinaryFormatter = new BinaryFormatter();
    objBinaryFormatter.Serialize(objMemoryStream, pObject);
    objMemoryStream.Position = 0;
    Object objReturnedObject = (object)objBinaryFormatter.Deserialize(objMemoryStream);
    objMemoryStream.Flush();
    objMemoryStream.Close();
    objBinaryFormatter = null;
    return objReturnedObject;

            }
            catch (Exception objException)
            {
    
                throw;
            }
    

    }

    Please guide me which is the best practice that I should follow. Is there any difference in the approches. There is no constrant to serialize some attribute of the class, the whole object should be serialized. Regards,

    modified on Tuesday, February 26, 2008 8:11 AM

    L 1 Reply Last reply
    0
    • F free_soul424

      Hi, I am facing an issue in serialization. I have a class that implement ISerializable interface. Actually I want to make my object to travel on the network. If I don’t implemetn the ISerializable interfce and use the following code I can get the same functionality.

      public static Object GetSerializedObject (Object pObject)
      {
      try
      {
      BinaryFormatter objBinaryFormatter = new BinaryFormatter();
      MemoryStream objMemoryStream = new MemoryStream();
      objBinaryFormatter = new BinaryFormatter();
      objBinaryFormatter.Serialize(objMemoryStream, pObject);
      objMemoryStream.Position = 0;
      Object objReturnedObject = (object)objBinaryFormatter.Deserialize(objMemoryStream);
      objMemoryStream.Flush();
      objMemoryStream.Close();
      objBinaryFormatter = null;
      return objReturnedObject;

              }
              catch (Exception objException)
              {
      
                  throw;
              }
      

      }

      Please guide me which is the best practice that I should follow. Is there any difference in the approches. There is no constrant to serialize some attribute of the class, the whole object should be serialized. Regards,

      modified on Tuesday, February 26, 2008 8:11 AM

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      You don't need to implement the ISerializable interface. Just decorate your class with the [Serializable] attribute and you are fine.

      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