Saturday, March 24, 2012

Serializing an object from a DLL

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 fro
m
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.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 f
rom
> 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 Sessio
n.
> 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.

0 comments:

Post a Comment