开发者

WCF "DataContext accessed after Dispose"

开发者 https://www.devze.com 2022-12-26 00:04 出处:网络
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 unders

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 rea开发者_StackOverflowd 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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消