views:

568

answers:

4

I have a POCO (plain old clr object) stored in session, and would like to be able to reference properties from that object from within another process (B). I don't want the stand-alone process (B) to require a reference to the dll in which the poco's class is defined. Is it possible to convert the saved object (in session) to something readable (e.g. xml) without referencing the object's class?

+1  A: 

you cant you need the assembly to get the metadata of the object, maybe you can avoid the reference to the dll and use reflection.

Oscar Cabrero
A: 

If you just need a snapshot of the object, then yes, you can simply serialize it (or just the properties you're interested in) and then pass the serialized data to process B. The XmlSerializer class probably provides the simplest way to serialize the object and then process B can read the data using any standard XML parser.

C. Dragon 76
How would you use the XmlSerializer without having a reference and knowing the type?
joshua.ewer
Process B can use standard XML techniques to "deserialize" the object.
Dan
@JDaniel: Agreed, once it's in Xml. Without knowing the type, how can you serialize it in the first place?
joshua.ewer
I believe jmaddrey was trying to avoid referencing the DLL from process B. Presumably process A is already referencing the DLL.
C. Dragon 76
+1  A: 

You would have to create your own custom code to serialize and/or deserialize the object.

Without a reference to the assembly .NET does not have the needed meta data to do the work for you.

You can just add an attribute to the generated XML to specify the object type.

<Object Type="1">
    <Property1>Value</Property1>
</Object>

Of course the destination code would need to know what to do with this type attribute, but you would not need to reference the actual .NET assembly.

Dana Holt
A: 

Forgetting about how to serialize it - how are you going to retrieve the data in another process. What is this other process? If it's not another ASP.NET page, then it will have no access to Session state!

John Saunders
Perhaps "process" was not the best choice of words. The dlls are executing in the same process (asp.net). The other dll (previously referred to as B) is shared by many apps. The session variable I want to deserialize is specific to one app. I am trying to avoid the shared dll having a "one-off".
Jeremy
How will this data be used by Assembly B when it is running in Web App A? What will Assembly B do when it is running in a different application, and are the other applications all web apps?
John Saunders