Self tracking POCO entities cannot serialize member ObjectChangeTracker.ObjectsRemovedFromCollectionProperties because it implements IDictionary in web method

Posts   
 
    
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 09-Jul-2010 18:52:55   

Hi

I'm have searched everywhere and cannot find a fix for the following error in my web service.

"Cannot serialize member myNamespace.ObjectChangeTracker.ObjectsRemovedFromCollectionProperties of type myNamespace.ObjectsRemovedFromCollectionProperties, because it implements IDictionary."

I hope you can help.

Here's some more detail:

I'm using LLBLGen Pro V3 with VS 2010 (C#) and SQL Server 2005.

Using SD.EntityFramework.v4 and SD.EntityFramework.v4(self tracking POCO entities) I have successfully generated the 2 (Model and Persistence) projects. My web service references both these projects and in the web reference there is one simple web method:

[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class myService : System.Web.Services.WebService { [WebMethod] public void AddUser(UserEntityClass user) { } }

This compiles fine, however, every time I try to view the webservice in a web browser I get the above error. It is not serialising the entity classes properly.

In theory this UserEntityClass should be a POCO, however LLBLGen Pro generates this class with an inheritance from the CommonEntityBase. This is what is causing the problem I think. My UserEntityClass is a superclass with 5 TargetPerEntity subclasses I hope thats not an issue.

Is there some property I have to set before generating the code? Is there something else I have to reference? There arent many topics about using self tracking entities with web services on the web and I'm stumped....

Thanks in advance!

EDIT: oops sorry I just realised I posted this in the wrong queue. Should prob be in the General one. flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jul-2010 10:56:37   

POCO just means there's no inheritance from a central framework base class. The generated commonentitybase class is a simple poco class which doesn't inherit from any class.

We based our code on MS' STE code so it's a bit of a surprise you get this error. What's the exact stacktrace ?

(edit) the ObjectChangeTracker class might be the problem, but that one is the same as in MS' STE templates... It's a class which is also generated in code. Do you use webservices or WCF?

A small repro case (i.e. so we know how you've setup your webservice) would help us so we can see with EF v4 native code what we might did wrong.

Frans Bouma | Lead developer LLBLGen Pro
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 10-Jul-2010 18:48:02   

Hi thanks for the replying over the weekend.

Even though MS STE uses ObjectChangeTracker I don't think it tries to serialise it does it?

Can you tell me what you mean by a repo case? If you're referring to source code I'm not sure what else I can supply to you other than the web service code. Is there an easy way to show you the properties of my LLBLGen pro properties?

The stack trace for the error is as follows:

[NotSupportedException: Cannot serialize member myNamespace.ObjectChangeTracker.ObjectsRemovedFromCollectionProperties of type myNamespace.ObjectsRemovedFromCollectionProperties, because it implements IDictionary.] System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo) +925084 System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference) +4044946 System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError) +192 System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo) +85 System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo) +89 System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +264 System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +402 System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1502

[InvalidOperationException: There was an error reflecting type 'myNamespace.ObjectChangeTracker'.] System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1806 System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +2297 System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter) +105 System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +1151

[InvalidOperationException: There was an error reflecting property 'ChangeTracker'.] System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +2132 System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +402 System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter) +2468 System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter) +402 System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1502

[InvalidOperationException: There was an error reflecting type 'myNamespace.EntityClasses.myEntityClass'.] System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) +1806 System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +2297 System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +706 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +298

[InvalidOperationException: There was an error reflecting 'whv'.] System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, RecursionLimiter limiter) +941 System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement, Boolean rpc, Boolean openModel, XmlMappingAccess access) +137 System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle paramStyle, String elementName, String elementNamespace, Boolean nsIsDefault, XmlReflectionMember[] members, Boolean validate, Boolean openModel, String key, Boolean writeAccess) +119 System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +4048

[InvalidOperationException: Method myService.Hello can not be reflected.] System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs) +6746 System.Web.Services.Description.SoapProtocolReflector.ReflectMethod() +136 System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding) +2255 System.Web.Services.Description.ProtocolReflector.Reflect() +721 System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors) +596 System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url) +180 System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri) +156 System.Web.Services.Protocols.DocumentationServerProtocol.Initialize() +352 System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +124

[InvalidOperationException: Unable to handle request.] System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) +335 System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +176

[InvalidOperationException: Failed to handle request.] System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +347 System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212 System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47 System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +203 System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

Thanks for your help.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Jul-2010 11:20:28   

nathan.liu wrote:

Hi thanks for the replying over the weekend.

Even though MS STE uses ObjectChangeTracker I don't think it tries to serialise it does it?

yes it serializes it (the webservice) because it's the change tracker for the entities, it's a class in the helper classes and referenced by the entity class (we placed it in the commonentitybase class but that doesn't matter, MS placed it in the entity class itself)

Can you tell me what you mean by a repo case? If you're referring to source code I'm not sure what else I can supply to you other than the web service code. Is there an easy way to show you the properties of my LLBLGen pro properties?

The webservice code + llblgenproj file.

But you first have to answer the question what you use: webservice or WCF. The STEs are for WCF, not for good old webservices.

Frans Bouma | Lead developer LLBLGen Pro
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 11-Jul-2010 12:27:17   

Hi

Yes I'm using a web service, not WCF. There are hardly any concrete examples of EF with web services, however, in their articles MS always refer to the fact that its for both WCF and web services.

I hope this is not an issue. If there are any tutorials or documentation on LLBLGen pro STEs that you could refer to me, that would be great.

If I was using WCF, would I simply need to reference both the STE projects (Model + Persistence) in my WCF service to have is set it up? Is there anything else I need to reference?

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Jul-2010 18:13:55   

nathan.liu wrote:

Hi

Yes I'm using a web service, not WCF. There are hardly any concrete examples of EF with web services, however, in their articles MS always refer to the fact that its for both WCF and web services.

You need to use WCF as the generated code uses WCF attributes to control the serialization. If you really don't want to use WCF, you should normal poco's so not the selftracking entities

I hope this is not an issue. If there are any tutorials or documentation on LLBLGen pro STEs that you could refer to me, that would be great.

If I was using WCF, would I simply need to reference both the STE projects (Model + Persistence) in my WCF service to have is set it up? Is there anything else I need to reference? thanks

And of course the EF4 framework assembly shipped with .NET 4.

On the client, you have to reference the Model project. Not the persistence project.

Frans Bouma | Lead developer LLBLGen Pro
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 12-Jul-2010 02:33:04   

Hi Otis

Ok I'm now trying to run this with WCF instead of the old webservice.

I now have a very basic WCF service with 1 service contract and 1 operation contract.

[ServiceContract] public interface IService1 { [OperationContract] void SetUser(UserEntity user); }

public class Service1 : IService1 { public void SetUser(UserEntity user) { } }

I have the same LLBLGen projects generated using SD.EntityFramework.v4 and SD.EntityFramework.v4 (self tracking POCO entities).

In the WCF I reference both the Model and Persistence projects and system.data.entity.

If i just compile the WCF service as it is, and then try to browse the .svc file in the browser i get the following error:

Type 'myNamespace.EntityClasses.User' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base type 'myNamespace.EntityClasses.CommonEntityBase' with DataContractAttribute or SerializableAttribute, or removing them from the derived type.

So once again the CommonEntityBase is causing me grief.

Now if I go into the CommonEntityBase in the model project and add the [DataContract(IsReference = true)] attribute to the class everything now works and I can browse the WCF service and connect to it via my client.

Is there some property that i failed to set to make the CommonEntityBase a datacontract in the LLBLGen designer? Is there another approach to get this working? I hope its not a bug!

I'll try using this with my old web service tomorrow as I have a nagging suspicion that it might be the same problem.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 12-Jul-2010 11:01:46   

You didn't do anything wrong, it's a bug in the template. We'll correct it.

We'll also correct the other templates where we forgot attributes.

Frans Bouma | Lead developer LLBLGen Pro
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 12-Jul-2010 11:40:59   

oh I see, well thats a boost to my ego, but a setback to the project. haha...

How would we be able to get our hands on the new templates? Do we have to wait for the next release?

thanks

Nathan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 12-Jul-2010 12:01:23   

We've analyzed the templates, made several changes and they're all available in the next build, released later today (12-jul) if everything goes to plan.

Btw, to test the service, you can use the WCF Test Client from the C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE folder, if you didn't know that already wink

Frans Bouma | Lead developer LLBLGen Pro
nathan.liu
User
Posts: 11
Joined: 09-Jul-2010
# Posted on: 12-Jul-2010 12:54:08   

Thankyou Otis

I will get the latest release and see how things go from there.

Cheers.