[DataContract] serialization vs [Serializable]

Topics: Developer Forum, Project Management Forum, User Forum
Jan 9, 2008 at 8:54 PM
Hey guys. Thanks for all the hard work on a great tool.

I have a question about serialization.

Since we use WCF in our shop, all our business entities are decorated with DataContract and DataMember instead of Serializable.

So, when I attempt to add them to cache, I get a System.Runtime.Serialization.SerializationException that says my object is not marked Serializable.

Does this mean that indeXus.Net SharedCache will not be compatible with custom WCF business entities? Or is there something that I missed, or perhaps a workaround any of you have used?

Jan 10, 2008 at 9:03 AM
Edited Jan 10, 2008 at 9:19 AM
hi thanks for your feedback,

I will try to make some tests within the next few day's and will checkout how to handle this issue. it would be help if you could post us some code which you are using -> best would be if you can send it to our email:

sharedcache AT indexus.Net

does this sample fit your environment: msdn datacontract sample
Jan 10, 2008 at 3:40 PM
Mr. Schuetz,

Thanks for the quick reply.

I am not sure I am allowed to email or post portions of our code. However, from your example... This is the basic idea...

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace SharedObjects
public class Sample
public string Name = "Contains a Name";

public int Numeric = 456;

public List<string> ListData;

public Sample()
this.ListData = new List<string>();
this.ListData.Add(@"Sample Data 1");
this.ListData.Add(@"Sample Data 2");
this.ListData.Add(@"Sample Data 3");
this.ListData.Add(@"Sample Data 4");
this.ListData.Add(@"Sample Data 5");

I went back and did some more testing, and it seems as though as long as I add both Serializable and DataContract attributes to our DTOs, that everything works fine. My only concern was that by adding both attributes, I could confuse either the .net binary serializer, or the WCF serializer, but so far there do not appear to be any side effects of adding both.

Thanks again, and I will post back as we test more with it.
Jan 10, 2008 at 5:26 PM
okey great, I'm waiting for more information and looking forward to hear good news.
Dec 18, 2008 at 11:50 PM

Just wanted to update the group.  So far we haven't had any problems adding both Serializable and DataContract attributes at the same time.