asp.net mvc - XML Serialization Error In Nhibernate with MVC4 Web API -
hello creating web api in mvc4 nhibernate. when calling web api throws error. here error.
<error><message>an error has occurred.</message><exceptionmessage>the 'objectcontent`1' type failed serialize response body content type 'application/xml; charset=utf-8'.</exceptionmessage><exceptiontype>system.invalidoperationexception</exceptiontype><stacktrace/><innerexception><message>an error has occurred.</message><exceptionmessage>type 'nhibernate.collection.generic.persistentgenericset`1[[mvcangular.models.bankaccount, mvcangular, version=1.0.0.0, culture=neutral, publickeytoken=null]]' info contract name 'arrayofbankaccount:http://schemas.datacontract.org/2004/07/mvcangular.models' not expected. consider using datacontractresolver or add together types not known statically list of known types - example, using knowntypeattribute attribute or adding them list of known types passed datacontractserializer.</exceptionmessage><exceptiontype>system.runtime.serialization.serializationexception</exceptiontype><stacktrace> @ system.runtime.serialization.xmlobjectserializerwritecontext.serializeandverifytype(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, boolean verifyknowntype, runtimetypehandle declaredtypehandle, type declaredtype) @ system.runtime.serialization.xmlobjectserializerwritecontext.serializewithxsitype(xmlwriterdelegator xmlwriter, object obj, runtimetypehandle objecttypehandle, type objecttype, int32 declaredtypeid, runtimetypehandle declaredtypehandle, type declaredtype) @ system.runtime.serialization.xmlobjectserializerwritecontext.internalserialize(xmlwriterdelegator xmlwriter, object obj, boolean isdeclaredtype, boolean writexsitype, int32 declaredtypeid, runtimetypehandle declaredtypehandle) @ system.runtime.serialization.xmlobjectserializerwritecontext.internalserializereference(xmlwriterdelegator xmlwriter, object obj, boolean isdeclaredtype, boolean writexsitype, int32 declaredtypeid, runtimetypehandle declaredtypehandle) @ writecustomerinfotoxml(xmlwriterdelegator , object , xmlobjectserializerwritecontext , classdatacontract ) @ system.runtime.serialization.classdatacontract.writexmlvalue(xmlwriterdelegator xmlwriter, object obj, xmlobjectserializerwritecontext context) @ system.runtime.serialization.xmlobjectserializerwritecontext.writedatacontractvalue(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, runtimetypehandle declaredtypehandle) @ system.runtime.serialization.xmlobjectserializerwritecontext.serializewithoutxsitype(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, runtimetypehandle declaredtypehandle) @ system.runtime.serialization.xmlobjectserializerwritecontext.internalserialize(xmlwriterdelegator xmlwriter, object obj, boolean isdeclaredtype, boolean writexsitype, int32 declaredtypeid, runtimetypehandle declaredtypehandle) @ system.runtime.serialization.xmlobjectserializerwritecontext.internalserializereference(xmlwriterdelegator xmlwriter, object obj, boolean isdeclaredtype, boolean writexsitype, int32 declaredtypeid, runtimetypehandle declaredtypehandle) @ writearrayofcustomerinfotoxml(xmlwriterdelegator , object , xmlobjectserializerwritecontext , collectiondatacontract ) @ system.runtime.serialization.collectiondatacontract.writexmlvalue(xmlwriterdelegator xmlwriter, object obj, xmlobjectserializerwritecontext context) @ system.runtime.serialization.xmlobjectserializerwritecontext.writedatacontractvalue(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, runtimetypehandle declaredtypehandle) @ system.runtime.serialization.xmlobjectserializerwritecontext.serializeandverifytype(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, boolean verifyknowntype, runtimetypehandle declaredtypehandle, type declaredtype) @ system.runtime.serialization.xmlobjectserializerwritecontext.serializewithxsitypeattoplevel(datacontract datacontract, xmlwriterdelegator xmlwriter, object obj, runtimetypehandle originaldeclaredtypehandle, type graphtype) @ system.runtime.serialization.datacontractserializer.internalwriteobjectcontent(xmlwriterdelegator writer, object graph, datacontractresolver datacontractresolver) @ system.runtime.serialization.datacontractserializer.internalwriteobject(xmlwriterdelegator writer, object graph, datacontractresolver datacontractresolver) @ system.runtime.serialization.xmlobjectserializer.writeobjecthandleexceptions(xmlwriterdelegator writer, object graph, datacontractresolver datacontractresolver) @ system.runtime.serialization.xmlobjectserializer.writeobjecthandleexceptions(xmlwriterdelegator writer, object graph) @ system.runtime.serialization.datacontractserializer.writeobject(xmlwriter writer, object graph) @ system.net.http.formatting.xmlmediatypeformatter.<>c__displayclass7.<writetostreamasync>b__6() @ system.threading.tasks.taskhelpers.runsynchronously(action action, cancellationtoken token)</stacktrace></innerexception></error>
we getting result in webapi. here schema of classess. have used iset int parent class
public class customerinfo { int _customerid; public virtual int customerid { { homecoming _customerid; } set { _customerid = value; } } string _name; [required] public virtual string name { { homecoming _name; } set { _name = value; } } public virtual iset<bankaccount> bankaccounts { get; set; } public virtual void setbankaccount(iset<bankaccount> bankact) { this.bankaccounts = bankact; } public virtual iset<bankaccount> getbankaccounts() { homecoming this.bankaccounts; } }
and method of web api
public ilist<customerinfo> get() { customerinfodal cd = new customerinfodal(); var lst = cd.getcustomer(); homecoming lst; }
we getting result in lst. while showing through web api shows error.
actually nhibernate iset<> not supported serialization. have fetch though json. ie can utilize fiddler see result.
asp.net-mvc nhibernate asp.net-web-api
No comments:
Post a Comment