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 ?
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').
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 !
Related
I am attempting to migrate a legacy vb.net application to .net standard and turn it into a nuget package. A good amount of it has been straight forward. I am currently hung up on this error caused by functions like this.
Public Property ErrorMessages As Collection
Get
ErrorMessages = _errorMessages
End Get
Set(value As Collection)
_errorMessages = value
End Set
End Property
If i import System.Collections.ObjectModelCollection(Of T) it is asking me for a type and i am unsure how to proceed. It turns my code into
Collection(Of,) and expects a second argument. Has anyone faced this before? Do i use a different import statement or how is this dealt with in vb now?
You should almost certainly replace Collection with Dictionary(Of TKey, TValue), using the dictionary type from the System.Collections.Generic namespace.
Once again, this requires you to fill in the genetic type arguments TKey and TValue with the actual types. You need to figure out from context which type fits the collection. The value of TKey is probably String since that’s the only key type VB6’ collections properly support. And given the name (ErrorMessages), TValue is probably String as well.
I have an IIS-hosted WCF service that connects to a SQL database backend using Entity Framework 4.1. Occasionally, I will receive the following exception:
An EdmType cannot be mapped to CLR classes multiple times. The
EdmType 'Model.EmailTemplate' is mapped more than once. (An item with
the same key has already been added.)
This happens rarely enough that I'm not sure it's even always the same class, but there's definitely nothing special about the class mentioned above, and it definitely does not appear in the edmx more than once! (I believe it simply blames the first class it tries to access after whatever happens that sends Entity Framework off the rails.)
The model is generated from the database tables using the designer and doesn't have any complicated mappings or anything.
When this happens, it will continue to throw that exception until I do an iisreset, and then when it comes back up it's perfectly happy.
This does not appear to be happening in production as far as I'm aware, but it has been happening in both dev and test, two different environments with different SQL server instances. In both cases, doing an iisreset makes it go away until the next time it becomes offended.
I can't reproduce this consistently enough to be sure when it happens and what is causing it. However, there are two possible things I can think of:
The WCF service and a win32 service share the same assemblies and configuration files to connect to the same database. I guess it's possible some sort of occasional combination of timing between the two of them is annoying one of them, but they're different processes and using different credentials so I'm not sure how they could be affecting each other...
There is a point where it talks to a second separate database, on which it calls some stored procedures using SqlCommand.ExecuteReader. It instantiates an EF context just to call ObjectContext.Translate<ResultSetType>(reader). The result set types that call takes as generic parameters aren't types that are mapped in the context (and notably nothing to do with the type mentioned in the exception above), they're just POCO. Nor are they even connecting to the same database as the object context is on, as the appropriate SqlDataReader is already ready to roll. The object context is just used as a convenient way of automatically translating entities from the other database. (This call would be static if a static Translate<T>(DbDataReader) existed.) This is probably what's tripping it up, as it's a bit of a hack and probably doesn't appreciate being used that way... but the block is wrapped in a using (with a TransactionScopeOption.Suppress using directly inside it), so I still feel like it shouldn't have this effect on subsequent calls made with other contexts instantiated later...
Anyone ever run into anything like this?
Edited to add: It is a MappingException, and the stacktrace is below.
at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAssemblyForType(Type type, EdmItemCollection edmItemCollection)
at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ELinq.ExpressionConverter.TryGetValueLayerType(Type linqType, TypeUsage& type)
at System.Data.Objects.ELinq.ExpressionConverter.GetCastTargetType(TypeUsage fromType, Type toClrType, Type fromClrType, Boolean preserveCastForDateTime)
at System.Data.Objects.ELinq.ExpressionConverter.CreateCastExpression(DbExpression source, Type toClrType, Type fromClrType)
at System.Data.Objects.ELinq.ExpressionConverter.ConvertTranslator.TranslateUnary(ExpressionConverter parent, UnaryExpression unary, DbExpression operand)
at System.Data.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter parent, UnaryExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
at System.Data.Objects.ELinq.ExpressionConverter.Convert()
at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.ObjectModel.ObservableCollection`1.CopyFrom(IEnumerable`1 collection)
at System.Collections.ObjectModel.ObservableCollection`1..ctor(IEnumerable`1 collection)
Suppose we have the following Service contract:
[ServiceContract]
public interface IPing
{
[OperationContract]
string Ping(string parameter1, string parameter2);
}
I'm wondering, how it would be possible to find a particular parameter value, say the value of parameter1 for example, in the System.ServiceModel.Channels.Message created server side.
Thanks!
It's the task of the IDispatchMessageFormatter to convert between the operation parameters and the Message object. Usually the message is created with a XML body, and the parameters are XML elements, but that's just one possible implementation (it's perfectly valid for a formatter to completely disregard the message and assign whatever values it sees fit for the operation parameters).
You can learn more about message formatters in the blog post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx.
I'm getting this error in my wcf services all of a sudden:
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior contract:
http://tempuri.org/:IListingService ----> System.MissingMethodException: No parameterless constructor defined
for this object.
at
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at
System.Activator.CreateInstance(Type type, Boolean nonPublic) at
System.Runtime.Serialization.SchemaExporter.InvokeGetSchemaMethod(Type clrType, XmlSchemaSet schemas, XmlQualifiedName stableName) at
System.Runtime.Serialization.SchemaExporter.ExportXmlDataContract(XmlDataContract dataContract) at
System.Runtime.Serialization.SchemaExporter.Export() at
System.Runtime.Serialization.XsdDataContractExporter.Export(Type type)
I have public constructors with no parameters in every single class and it still gives me this error. What am I missing?
Found the issue, I was using an OId for a property type (a 3rd party type from MongoDB), which had no default constructor. Changed this to an int and it started working. The weird thing though is that the OId property worked fine for weeks, I wonder what changed...
I had the same issue with a slightly different solution.
(Obviously, this is an old post, but for those who found this question like I did and the original answer didn't help...)
I think it's pretty reasonable to say that every object referenced by your Interface signature(s) need to be marked as serializable. Sometimes in simple projects, we don't think about this because many (or most?) of the native .NET objects we play with already have this ability. For example, "ObjId as Guid" wont cause any problems in the signature for an interface-implemented member.
The problem I experienced was that I had multiple custom objects ("Class1, Class2, whatever) as properties in the object that was actually referenced by my signature. THAT object (say MyMainClass) had the attribute set on it, but my custom property objects did not. As soon as I added the attribute to those classes, the error shown above went away.
I'm not 100% sure what the correct terminologies are but..
I have a class called InParams with two fields, a string and a long and their corresponding Property accessors to the fields. These are decorated with [DataContract] and [DataMember] respectively.
I have a WCF service method called void Test(InParams inParams)
The proxy generated fine with svcutil and I was able to set the long field, however when the service method is execute the long field is always 0, even though I explicitly set the long field. I looked at the soap envelope and don't see a tag for my long field.
When I change the long field to a string field it gets serialized. This is the same for ints as well.
Am I missing an attribute or something?
can you post a sample? double check to:
ensure class has [DataContract()] decoration
ensure PUBLIC properties have [DataMember()] decoration
Ensure your proxy class is up to date by removing/regenerating it. See if that makes a difference?
If you have a boolean YourPropertyNameSpacified property on the client in addition to YourPropertyName, you must set it to true on the client. This goes for all fields of value type, I believe. Also see WCF service proxy not setting "FieldSpecified" property.
In addition to doing what Tanner mentioned, longs and ints are clearly supported by the DataContractSerializer.
.NET Framework primitive types. The following types built into the .NET Framework can all be serialized and are considered to be primitive types: Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, Boolean, Char, Decimal, Object, and String.Link