0

The following error occurs whenthe client code running in CF 3.5 on a windows mobile 6.5 device tries to call our wcf service... before it ever even makes the call.

What is odd is that the exception DOES NOT occur when running under the debugger in VS and the phone is connected to the PC via the USB cable... The call works as expected.. data goes back and forth as it is supposed to...

But when running on its own, the CFClientBase code generates the following Stackoverflow Exception ??

This happens for all service calls, not just the one... Any Ideas ?

StackOverflowException

   at System.Reflection.CustomAttribute.GetObject()
   at System.Reflection.CustomAttribute.CheckConsistencyAndCreateArray(CustomAttribute caItem, Type caType)
   at System.Reflection.CustomAttribute.GetCustomAttributes(MemberInfo member, Type caType, Boolean inherit)
   at System.Reflection.CustomAttribute.GetCustomAttributes(Type type, Type caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Boolean inherit)
   at System.Xml.Serialization.TypeAttributes..ctor(ICustomAttributeProvider prov)
   at System.Xml.Serialization.TypeAttributes..ctor(ICustomAttributeProvider prov, XmlAttributes xmlAtts)

at System.Xml.Serialization.XmlSerializationReflector.AddType(Type type, Boolean encoded, String defaultNS, Boolean genericNullableArg)
   at System.Xml.Serialization.XmlSerializationReflector.FindType(Type type, Boolean encoded, Boolean genericNullableArg, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializationReflector.FindType(Type type, Boolean encoded, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializationReflector.ResolveLiteralTypeUsingDeclaredType(Type memberType, String defaultNS, LogicalType& type, LogicalType& elementType, Boolean& isArray)
   at System.Xml.Serialization.XmlSerializationReflector.ResolveLiteralType(String attrDataType, Type attrType, Type memberType, String defaultNS, Boolean& isArray, LogicalType& type, LogicalType& elementType)
   at System.Xml.Serialization.XmlSerializationReflector.ReflectXmlElementAttributes(Type memberType, LogicalMemberValue memberValue, String memberName, LiteralAttributes attrProv, AccessorCollection memberAccessors, String defaultName, String defaultNS, Type& serializingType, Boolean& shouldBeOrdered)
   at System.Xml.Serialization.XmlSerializationReflector.ReflectLiteralMemberValue(Type memberType, String memberName, LiteralAttributes attrProv, String defaultName, String defaultNS, IEntityFinder memberFinder, Boolean canRead, Boolean canWrite, Boolean& shouldBeOrdered)
   at System.Xml.Serialization.XmlSerializationReflector.ReflectMemberValue(Type memberType, ICustomAttributeProvider attrProv, String defaultName, String defaultNS, IEntityFinder memberFinder, Fetcher fetcher, Fixup fixup, MemberValueCollection members, Boolean encoded, Boolean canRead, Boolean canWrite, Byte& specialType, Boolean& shouldBeOrdered)
   at System.Xml.Serialization.XmlSerializationReflector.addComplexTypeMemberHelper(Type type, MemberInfo member, Boolean encoded, String defaultNS, Boolean& shouldBeOrdered, IEntityFinder choiceFinder, MemberValueCollection members, String typeNS, String defaultMemberNS, Int32& sequenceId)
   at System.Xml.Serialization.XmlSerializationReflector.AddComplexType(Type type, TypeAttributes attrs, String typeName, String typeNS, Boolean typeIsNullable, Boolean encoded, String defaultNS, Boolean genericNullableArg)
   at System.Xml.Serialization.XmlSerializationReflector.AddType(Type type, Boolean encoded, String defaultNS, Boolean genericNullableArg)
   at System.Xml.Serialization.XmlSerializationReflector.FindType(Type type, Boolean encoded, Boolean genericNullableArg, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializationReflector.FindType(Type type, Boolean encoded, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializationReflector.ReflectIncludedTypes()
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, String defaultNamespace)
   at Microsoft.Tools.ServiceModel.CFClientBase`1.CFContractSerializer.createSerializer(XmlQualifiedName wrapper)
   at Microsoft.Tools.ServiceModel.CFClientBase`1.CFContractSerializer..ctor(CFContractSerializerInfo info)
   at Microsoft.Tools.ServiceModel.CFClientBase`1.GetContractSerializer(CFContractSerializerInfo info)
   at Microsoft.Tools.ServiceModel.CFClientBase`1.Invoke[TREQUEST,TRESPONSE](CFInvokeInfo info, LogIntoServerRequest request)
   at WCFService.WOService.WOServiceClient.LogIntoServer(LogIntoServerRequest request)
   at WCFService.WOService.WOServiceClient.LogIntoServer(SmartPhoneLoginCredentials creds)
   at RescoMobileApp.Common.Classes.loginClass.LogIntoServer()

Edit

It appears that even though I am using DTOs to serialize across the wire... Somehow my EF Entity Classes are being sent in the schema ??

And for some reason those types are trying to be constructed when the service calls are made ??

How do I keep the classes out of the schema ? If there is a reference to the namespace of the Entities is that enough for WCF to pull those classes into the schema ?

Greg Foote
  • 171
  • 11

2 Answers2

0

Normally a stackoverflow exception occurs during serialization when you have a recursion problem in your object graph - an 'infinite lookup'. So, for example, you have a Class, which has a collection of Student; each Student has some Classes, each Class has a collection of Student, and so on forever.

Your problem doesn't occur running under the debugger, so it's probably not the scenario I've described, but there's a similar scenario where you have a large object graph and are attempting to serialize the entire graph. I don't know much about compact framework, but it's likely that the stack is smaller (hence the stackoverflow on the device but not in visual studio).

What kind of request are you making? Evidently you are serializing a lot of data; how deep does it go? Are you able to make the request work with a smaller dataset?

I'd suggest trying a much smaller request first, and check whether you are sending more data than required over the wire (or 'air').

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169
  • Every request fails... Even a very small object graph of 9 instances of a class with 4 properties.... I am going to try and re-load the CF framework on the phones perhaps one or more DLLs is the wrong version or corrupt – Greg Foote Apr 26 '12 at 13:10
  • You were correct, the SO exception was due to the limited memory and stack on the CF.... Got rid of the entities that I wasn't aware were being included in the xsd docs and that did the trick ! – Greg Foote Apr 26 '12 at 18:49
0

It turns out that an entity type was exposed to the WCF service interface and that it was not decorated with any DataContract or DataMember attributes so the WCF service apparently pulled in every entity in the namespace(s) via navigation properties on the entities themselves...

Applying DataContract to the class and then DataMembers ONLY on the scalar properties got me what I was after and left out all of the other types that I did not want serialized

Thanks !

Greg Foote
  • 171
  • 11
  • That's interesting because `DataContract` and `DataMember` are really only used to ensure certain objects and properties are serialized, not to exclude those that are decorated. – Kirk Broadhurst Apr 26 '12 at 22:13