duplicate properties created for class with attributes “DataContract” and “Serializable”

I have a class with 2 attributes on it, "DataContract" and "Serializable". This class is being used in a service. This service is being consumed by a project. I have added the reference of the service in the project by using the "add service reference" functionality of VS (Right Click on references -- Add -- Service Reference). Whenever I add the reference of the service, duplicate properties of the class is created in the Reference.cs file of the service reference, 1 with "DataMember" attribute and other with "Serializable" attribute. This is causing a build error. If I do not put the Serializable attribute, the service reference works fine with just 1 set of properties of the class with "DataMember" attribute.

Any idea why is this happening and what can we do to avoid this? Please note that both the attributes are required for the class i.e. I cannot remove any of the attributes.


Can you explain why you need both the attributes?

DataContractSerializer works fine with Serializable attribute.

But, for BinaryFormattor to work, you need Serializable attribute.

Find a way to get rid of DataContract attribute.


WCF uses DataContractSerializer by default to serialize/deserialize objects over channels. According to MSDN documentation,

@ DataContractSerializer Class

// You must apply a DataContractAttribute or SerializableAttribute
// to a class to have it serialized by the DataContractSerializer.

So, for WCF to work, you can get rid of DataContracts.

@Samar The best way would be to use only DataContract attribute, as it internally makes the Serializable attribute come in to picture (by default).

Need Your Help

Gwt Hosted Mode Server Side Reloading

gwt server-side mode hosted

Whenever I made code changes in GWT client side files I can just reload the browser or press "reload webserver" and the changes will be applied instantly. However, it doesn't work like that when I ...

Run timed PHP function via SQL

php sql execute

Is there a way to run a PHP file automatically every hour?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.