Serializing an object from a DLL

Discussion in 'ASP .Net' started by =?Utf-8?B?SGFycnk=?=, Nov 15, 2007.

  1. I am using SQL to hold session state. My problem is that I have an object
    that I want to store in Session State. I can not mark the class it comes from
    as Serializable because it is from a DLL that I do not have the code for.
    There must be an easy way to do this I just can't figure it out.


    This is the code that Serializes the item that I want to place in a Session.

    private string Serialize(SessionStateItemCollection items)
    {
    MemoryStream ms = new MemoryStream();
    BinaryWriter writer = new BinaryWriter(ms);

    if (items != null)
    items.Serialize(writer);

    writer.Close();

    return Convert.ToBase64String(ms.ToArray());
    }

    I'd really appreciate anyone who could help.
     
    =?Utf-8?B?SGFycnk=?=, Nov 15, 2007
    #1
    1. Advertising

  2. unless its sealed, make a new object that inherits from it, and enable
    serialization.

    the underlying object may not really support serialization (use of unmanged
    code, active streams / connections, non-serializable objects). in this case
    you can write a custom serializier read/write out the properties, and
    perform required initialization.

    -- bruce (sqlwork.com)


    "Harry" wrote:

    > I am using SQL to hold session state. My problem is that I have an object
    > that I want to store in Session State. I can not mark the class it comes from
    > as Serializable because it is from a DLL that I do not have the code for.
    > There must be an easy way to do this I just can't figure it out.
    >
    >
    > This is the code that Serializes the item that I want to place in a Session.
    >
    > private string Serialize(SessionStateItemCollection items)
    > {
    > MemoryStream ms = new MemoryStream();
    > BinaryWriter writer = new BinaryWriter(ms);
    >
    > if (items != null)
    > items.Serialize(writer);
    >
    > writer.Close();
    >
    > return Convert.ToBase64String(ms.ToArray());
    > }
    >
    > I'd really appreciate anyone who could help.
     
    =?Utf-8?B?YnJ1Y2UgYmFya2VyIChzcWx3b3JrLmNvbSk=?=, Nov 15, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,778
  2. Natan
    Replies:
    5
    Views:
    1,607
    Natan
    Sep 27, 2004
  3. learningjava

    de/serializing a graphics object

    learningjava, Jan 29, 2004, in forum: Java
    Replies:
    2
    Views:
    332
    learningjava
    Jan 30, 2004
  4. asd

    Serializing DOM object

    asd, Jun 8, 2005, in forum: Java
    Replies:
    3
    Views:
    422
  5. H. Simpson
    Replies:
    4
    Views:
    284
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page