Is is possible to Serialize/deserialize an object without knowing its type?

I would like to make our front end developers able to store any object in the database.

Like this:

void Business.StoreObject(string key, object o)

object Business.GetStoreObject(string key)

I then want to serialize the object and store it as a varbinary in the database.

The UI should then be able to retrieve it again and cast it to its specific type.

I will need to serialize this general object without knowing what is in it and then deserialize it again. Is this even possible? Usually I would use the type when duing this.

Can I get some kind of type info on the object so I can do this without having the type on the business tier?

[688 byte] By [Siteadm] at [2007-12-27]
# 1

You can do that by using binary serialization, the type information (basically the full type name) is included in the serialization information. The business tier will need to have the type available otherwise it won't be able to deserialize it and pass it back.

You could achieve something similar using XMLSerialization, you would need to pass an XmlNode to the business tier and store that directly in the database.

The second approach has a few advantages:

1. Performance: The business tier wouldn't need to deserialize and serialize (should be able to store the Xml document directly)

2. Availability: The Xml in the database would not be tied to any particular CLR type, therefore you can access your data using any old XmlParser, XmlSerializer etc...

JesusRuiz-MSFT at 2007-9-5 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...
# 2

Hi Jesus

Thanks for answering my post.

I can't be sure to have the type on the business tier.

The second solution you are describing. I could use that with binary serialization also right? (By taking/returning a byte array.)

Siteadm at 2007-9-5 > top of Msdn Tech,.NET Development,.NET Remoting and Runtime Serialization...

.NET Development

Site Classified