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.
Related
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)
I have a IUserType defined class and I want to use it as an Id of a table. When using Native generator I get an exception
InnerException: System.InvalidOperationException
Message=Identity type must be integral (int, long, uint, ulong)
Source=FluentNHibernate
My next step is to investigate custom generators but I wanted to verify that its possible to use user types as Ids.
So, can it be done?
I am dealing with concurrency issues in nhibernate and I am not really sure if I am doing right. I use a version field and when the transaction gets comitted, I think an StaleObjectStateException will get thrown if the version field was changed by another process. I catch this exception and handle that case and it seems to work.
But what I am wondering about is, that every time the exception is thrown, NHibernate produces an ERROR in my log4net-Logfile. I have set the loglevel for NHibernate to ERROR because I think that if an error occurs that should interest me. But I am not interested in all the messages about some concurrency conflict, because I don't regard that as an ERROR.
So it might be that I am doing something completely wrong? Is it the right way to deal with concurrency by catching the exception?
update: this is what nhibernate puts in my logfile:
2012-06-21 16:47:30,546 ERROR NHibernate.Event.Default.AbstractFlushingEventListener: Could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Delta.FollowUp.Model.CFollowUp#60003]
bei NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:Zeile 2780.
bei NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:Zeile 2692.
bei NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:Zeile 3000.
bei NHibernate.Action.EntityUpdateAction.Execute() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Action\EntityUpdateAction.cs:Zeile 79.
bei NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 136.
bei NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 126.
bei NHibernate.Engine.ActionQueue.ExecuteActions() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs:Zeile 170.
bei NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs:Zeile 241.
If you don't want to log NHibernate errors, just remove the logger for NHibernate, set it at the FATAL level, or filter the exceptions somehow.
You can still catch the exception, handle it, rethrow it, log it, whatever.
What you do when there's a concurrency issue depends on the app. In a lot of cases it is sufficient to catch the exception and retry the unit of work - but defining the unit of work is where it can get tricky. Depending on your situation, it might be sufficient to load the entity again and make the changes again and then save it, but that really depends on your application.
Basically that exception means that another thread/process has changed the entity in the database, so you need to now react accordingly. NHibernate is logging it as an error because the use of a version field implies optimistic concurrency where you are assuming that nothing else is going to change the row(s) you're changing, so if something does change one of those rows then you need to handle it.
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 !
The ECMA Common Language Infrastructure documentation says this about the CIL "isinst class" instruction:
Correct CIL ensures that class is a valid typeref or typedef or typespec token indicating a class, and
that obj is always either null or an object reference.
This implies that a valuetype is not allowed, right? But mscorlib.dll contains a method System.RuntimeTypeHandle::Equals(object obj) with the following instruction:
IL_0001: isinst System.RuntimeTypeHandle
And System.RuntimeTypeHandle is a valuetype. Can anybody put me right here?
Have a look at the declaration of RuntimeTypeHandle:
.class public sequential ansi serializable sealed beforefieldinit RuntimeTypeHandle
extends System.ValueType
implements System.Runtime.Serialization.ISerializable
Although RuntimeTypeHandle is declared as a struct its representation in CIL is some kind of special class. In other words, you can imagine structs as special classes that inherit from System.ValueType and whose attributes follow a strict order.
With that in mind isinst would be callable with RuntimeTypeHandle. For what I interpret isinst is not limited to reference types at all as long as there is a class representing the type.
Let's say we write in C#:
var i = 4;
var b = i is Int32;
We get a compiler warning
Warning: The given expression is always of the provided ('int') type.
What happens? We assign 4 to i. ibecoms an int. On the next line iis being auto-boxed to its corresponding ReferenceType (class), so that the warning is obvious. We could even write
var b = i is int;
I hope this can contribute to some kind of clearification on this topic.