Datacontract Attribute Serializable

Posted on  by admin

Microsoft visual studio 2005 pro final dvd iso software. My current laptop which has the installation is out of warranty and old, I would like to install the Visual Studio 2005 Professional Edition to my new laptop, I am a registered user of the Visual Studio 2005 Professional edition. How /where to contact inorder to buy media DVD for this software.? Or if there is ISO.

  1. Datacontract Attribute Serializable Definition
Active4 years, 2 months ago

Datacontract Attribute Serializable Definition

I am trying to create a deep clone of an object using the following method.

This method requires an object which is Serialized i.e. an object of a class who is having an attribute 'Serializable' on it. I have a class which is having attribute 'DataContract' on it but the method is not working with this attribute. I think 'DataContract' is also a type of serializer but maybe different than that of 'Serializable'.

Can anyone please give me the difference between the two? Also please let me know if it is possible to create a deepclone of an object with just 1 attribute which does the work of both 'DataContract' and 'Serializable' attribute or maybe a different way of creating a deepclone?

Datacontract Attribute Serializable

Also serializable work on opt out model where in a field that don't want to get serialized has to mark itself as nonserialized, however DataContract works on OptIn approach where any property that wants to get serialized has to mark itself as DataMember.

Please help!

JasonMArcher
9,95610 gold badges49 silver badges49 bronze badges
samarsamarDatacontract
3,4806 gold badges36 silver badges68 bronze badges

3 Answers

Serializable

Serializable is needed for the BinaryFormatter to work.

DataContract and the DataMember attribute are used with the DataContractSerializer.

You can decorate a class with attributes for both serializers.

OdedOded
424k78 gold badges778 silver badges932 bronze badges

DataContract is used in WCF hence .NET 3.0+. In .net 2.0 or lower there is not DataContract, DataMember attribute, only Serializable.

As Oded said, if you want to use BinaryFormatter you have to decorate the type with Serializable.

Liviu M.Liviu M.
5,6231 gold badge34 silver badges61 bronze badges

I once did some inspection to an object structure via Reflection to find all assemblies required for deserialization and serialize them alongside for bootstrapping.

With a bit of work one could build a similar method for deep copying. Basically you need a recursive method that carrys along a Dictionary to detect circular references. Inside the method you inspect all fields about like this:

To get it working you need to add an output object and something like System.Runtime.Serialization.FormatterServices.GetUninitializedObject(Type type) to create the most shallowest copy (even without copying references) of each field's value. Finally you can set each field with something like field.SetValue(input, output)

However this implementation does not support registered event handlers, which is _un_supported by deserializing, too. Additionally each object in the hierarchy will be broken, if its class' constructor needs to initialize anything but setting all fields. The last point only work with serialization, if the class has a respective implementation, e.g. method marked [OnDeserialized], implements ISerializable,.. .

No answerNo answer

Not the answer you're looking for? Browse other questions tagged c#.netserializationclone or ask your own question.