开发者

No parameterless constructor defined for this object error

开发者 https://www.devze.com 2023-02-07 15:12 出处:网络
I\'m getting this error in my wcf services all of a sudden: An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:

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 开发者_C百科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.

0

精彩评论

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

关注公众号