3

I have a winform application in C# .NET framework 2 which I want to serialize its objects into xml files and to use these files in silverlight framework 4 by deserialize (c#).

Which serialize class is supported by framework 2 and 4?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
gln
  • 1,011
  • 5
  • 31
  • 61

2 Answers2

6

What's wrong with good ol' XmlSerializer?

You say you want to serialize objects into XML files anyway, and XmlSerializer is supported on version 2.0 of the .NET Framework as well as 4.0/Silverlight.

Check the "Other Versions" dropdown on the linked documentation page for any specific details that apply to particular versions of the Framework.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Just to remember: XML Serialization is also technology independent, you would be able to deserialize with systems written in other languages (ex: Java). But Binary Serliazation is also possible: http://stackoverflow.com/questions/203694/stability-of-net-serialization-across-different-framework-versions :) – JSBach Jan 14 '11 at 09:45
  • @Oscar: Yes, binary serialization is always an option. But the question specified a requirement to serialize objects into XML files. Additionally, it can be very difficult to share binary serialized data across two different applications, even within the same technology (in this case, .NET). You have to know the right tool for the job. – Cody Gray - on strike Jan 14 '11 at 09:47
  • platform independent binary serializers are readily available – Marc Gravell Jan 14 '11 at 09:55
  • @Marc: Sorry, by "tools", I meant choosing either XML serialization or binary serialization. The previous sentence was a secondary point: It's easier to break binary serialization than XML serialization with versioning issues, etc. There are libraries available for binary serialization beyond those provided by the .NET Framework, but from what I can tell in the question, those would be overkill. – Cody Gray - on strike Jan 14 '11 at 09:59
  • oh, I agree entirely that `BinaryFormatter` is inappropriate - but things like protobuf are free of things like versioning. But the OP wants xml, which is fine too ;p – Marc Gravell Jan 14 '11 at 10:09
1

XmlSerializer

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928