can Custom Serialization be used to move class instance data from one program to another?

  • Thread starter Thread starter camarkco
  • Start date Start date
Why does C# go out of it's way to prevent this?

It doesn't. What problem are you seeing? What are you trying to do?
Code samples would help.

The common mistake people make is using binary serialization, and
simply copying a class between two programs (assemblies) - however,
binary serialization cares about the source assembly, since it is
fully typed. A shared assembly, or some tricks in deserialization can
help here, or a simpler option is to use xml serialization which is
not restricted by assembly constraints (but has subtly different
behavior).

Marc
 
Actually, I think a better option here, if available is to use the
DataContractSerializer. This way, there is no requirements for the types to
be the same on both sides, just have the same contract.

Of course, using it to perpetuate poor design isn't a good thing, but
there might be instances where you want the same definition of the same type
in different assemblies.
 
Hi Mark,

I agree with Marc. C# doesn't go out of its way to prevent custom
serialization from being used to move class instance data from one program
to anthother.

Since you want to move class instance data from one program to another, I
suggest that you use XML Serialization. The following is some links which
may be helpful:

'Basics of .NET Framework Serialization '
http://msdn2.microsoft.com/en-us/library/ms233836(vs.80).aspx

'How to: Serialize an Object '
http://msdn2.microsoft.com/en-us/library/szzyf24s(VS.80).aspx

'How to: Deserialize an Object '
http://msdn2.microsoft.com/en-us/library/fa420a9y(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Mark,

How about the problem now?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top