views:

30

answers:

1

I have an application with numerous WCF services that make use of LINQ-To-SQL as the data access model. I am having lots of problems with the "DataContext accessed after Dispose" exception. I understand what this exception is and that it is occurring because I have not "initialised" the data that is trying to be accessed. I've read many articles that suggest that I called ToList() on any arrays before the parent object is returned by the service.

My issue is that I am getting this exception and I don't know where it is originating from and therefore I don't know what hasn't been initialised.

Can anyone advise how best to identify the root cause?

(I have used the MS Service Trace Viewer and this doesn't seem to give me any further information)

+1  A: 

I found the root cause of the issue was that there was a class in the linq-to-sql that was decorated with the DataContract attribute but needed to set the IsReference property to true ([DataContract(IsReference=true)]). There was also a property of that class that was not a DataMember and need to be ([DataMember(EmitDefaultValue=false)]). Setting these two attributes fixed my issue.

David Ward