c# - MVC returns invalid json when an exeption is thrown -
i have simple function
public actionresult getuserlist(int? departmentid) { return content(list.getjson(departmentid), "application/json"); }
i call angular
$http.post('/stockassignment/getuserlist', { departmentid: departmentid}).then( function (data) { /* ok, stuff */ }, function(data) { /* show error, witch should in data.data.msg } );
this works fine, until in list.getjson function throws error. display error using angular, result not valid json. here example of returned data:
{ "msg" : "unable process type 'anonymous type', because has no known mapping value layer. @ system.data.entity.core.objects.elinq.expressionconverter.newarrayinittranslator.typedtranslate(expressionconverter parent, newarrayexpression linq) @ system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression linq) @ system.data.entity.core.objects.elinq.expressionconverter.constanttranslator.typedtranslate(expressionconverter parent, constantexpression linq) @ system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression linq) @ system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.groupjointranslator.translate(expressionconverter parent, methodcallexpression call) @ system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.typedtranslate(expressionconverter parent, methodcallexpression linq) @ system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression linq) @ system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.onelambdatranslator.translate(expressionconverter parent, methodcallexpression call, dbexpression& source, dbexpressionbinding& sourcebinding, dbexpression& lambda) @ system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.selectmanytranslator.translate(expressionconverter parent, methodcallexpression call) @ system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.typedtranslate(expressionconverter parent, methodcallexpression linq) @ system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression linq) @ system.data.entity.core.objects.elinq.expressionconverter.convert() @ system.data.entity.core.objects.elinq.elinqquerystate.getexecutionplan(nullable`1 formergeoption) @ system.data.entity.core.objects.objectquery`1.<>c__displayclass7.<getresults>b__6() @ system.data.entity.core.objects.objectcontext.executeintransaction[t](func`1 func, idbexecutionstrategy executionstrategy, boolean startlocaltransaction, boolean releaseconnectiononsuccess) @ system.data.entity.core.objects.objectquery`1.<>c__displayclass7.<getresults>b__5() @ system.data.entity.sqlserver.defaultsqlexecutionstrategy.execute[tresult](func`1 operation) @ system.data.entity.core.objects.objectquery`1.getresults(nullable`1 formergeoption) @ system.data.entity.core.objects.objectquery`1.<system.collections.generic.ienumerable<t>.getenumerator>b__0() @ system.data.entity.internal.lazyenumerator`1.movenext() @ newtonsoft.json.serialization.jsonserializerinternalwriter.serializelist(jsonwriter writer, ienumerable values, jsonarraycontract contract, jsonproperty member, jsoncontainercontract collectioncontract, jsonproperty containerproperty) @ newtonsoft.json.serialization.jsonserializerinternalwriter.serializeobject(jsonwriter writer, object value, jsonobjectcontract contract, jsonproperty member, jsoncontainercontract collectioncontract, jsonproperty containerproperty) @ newtonsoft.json.serialization.jsonserializerinternalwriter.serializeobject(jsonwriter writer, object value, jsonobjectcontract contract, jsonproperty member, jsoncontainercontract collectioncontract, jsonproperty containerproperty) @ newtonsoft.json.serialization.jsonserializerinternalwriter.serializelist(jsonwriter writer, ienumerable values, jsonarraycontract contract, jsonproperty member, jsoncontainercontract collectioncontract, jsonproperty containerproperty) @ newtonsoft.json.serialization.jsonserializerinternalwriter.serialize(jsonwriter jsonwriter, object value, type objecttype) @ newtonsoft.json.jsonserializer.serializeinternal(jsonwriter jsonwriter, object value, type objecttype) @ norconsult.extensions.jsonhelpers.getjson(object o) in c:\users\hp\documents\visual studio 2017\projects\norconsult\norconsult\extensions\jsonhelpers.cs:line 57"}
angular not able read this, , throws error:
error: [$http:baddata] http://errors.angularjs.org/1.6.5/$http/baddata?p0=%7b%20%22msg%22%20%3a%20%22unable%20to%20process%20the%20type%20'anonymous%20type'%2c%20because%20it%20has%20no%20known%20mapping%20to%20the%20value%20layer.%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.newarrayinittranslator.typedtranslate(expressionconverter%20parent%2c%20newarrayexpression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.constanttranslator.typedtranslate(expressionconverter%20parent%2c%20constantexpression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.groupjointranslator.translate(expressionconverter%20parent%2c%20methodcallexpression%20call)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.typedtranslate(expressionconverter%20parent%2c%20methodcallexpression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.onelambdatranslator.translate(expressionconverter%20parent%2c%20methodcallexpression%20call%2c%20dbexpression%26%20source%2c%20dbexpressionbinding%26%20sourcebinding%2c%20dbexpression%26%20lambda)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.selectmanytranslator.translate(expressionconverter%20parent%2c%20methodcallexpression%20call)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.methodcalltranslator.typedtranslate(expressionconverter%20parent%2c%20methodcallexpression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.translateexpression(expression%20linq)%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.convert()%0d%0a%20%20%20at%20system.data.entity.core.objects.elinq.elinqquerystate.getexecutionplan(nullable%601%20formergeoption)%0d%0a%20%20%20at%20system.data.entity.core.objects.objectquery%601.%3c%3ec__displayclass7.%3cgetresults%3eb__6()%0d%0a%20%20%20at%20system.data.entity.core.objects.objectcontext.executeintransaction%5bt%5d(func%601%20func%2c%20idbexecutionstrategy%20executionstrategy%2c%20boolean%20startlocaltransaction%2c%20boolean%20releaseconnectiononsuccess)%0d%0a%20%20%20at%20system.data.entity.core.objects.objectquery%601.%3c%3ec__displayclass7.%3cgetresults%3eb__5()%0d%0a%20%20%20at%20system.data.entity.sqlserver.defaultsqlexecutionstrategy.execute%5btresult%5d(func%601%20operation)%0d%0a%20%20%20at%20system.data.entity.core.objects.objectquery%601.getresults(nullable%601%20formergeoption)%0d%0a%20%20%20at%20system.data.entity.core.objects.objectquery%601.%3csystem.collections.generic.ienumerable%3ct%3e.getenumerator%3eb__0()%0d%0a%20%20%20at%20system.data.entity.internal.lazyenumerator%601.movenext()%0d%0a%20%20%20at%20newtonsoft.json.serialization.jsonserializerinternalwriter.serializelist(jsonwriter%20writer%2c%20ienumerable%20values%2c%20jsonarraycontract%20contract%2c%20jsonproperty%20member%2c%20jsoncontainercontract%20collectioncontract%2c%20jsonproperty%20containerproperty)%0d%0a%20%20%20at%20newtonsoft.json.serialization.jsonserializerinternalwriter.serializeobject(jsonwriter%20writer%2c%20object%20value%2c%20jsonobjectcontract%20contract%2c%20jsonproperty%20member%2c%20jsoncontainercontract%20collectioncontract%2c%20jsonproperty%20containerproperty)%0d%0a%20%20%20at%20newtonsoft.json.serialization.jsonserializerinternalwriter.serializeobject(jsonwriter%20writer%2c%20object%20value%2c%20jsonobjectcontract%20contract%2c%20jsonproperty%20member%2c%20jsoncontainercontract%20collectioncontract%2c%20jsonproperty%20containerproperty)%0d%0a%20%20%20at%20newtonsoft.json.serialization.jsonserializerinternalwriter.serializelist(jsonwriter%20writer%2c%20ienumerable%20values%2c%20jsonarraycontract%20contract%2c%20jsonproperty%20member%2c%20jsoncontainercontract%20collectioncontract%2c%20jsonproperty%20containerproperty)%0d%0a%20%20%20at%20newtonsoft.json.serialization.jsonserializerinternalwriter.serialize(jsonwriter%20jsonwriter%2c%20object%20value%2c%20type%20objecttype)%0d%0a%20%20%20at%20newtonsoft.json.jsonserializer.serializeinternal(jsonwriter%20jsonwriter%2c%20object%20value%2c%20type%20objecttype)%0d%0a%20%20%20at%20norconsult.extensions.jsonhelpers.getjson(object%20o)%20in%20c%3a%5cusers%5chp%5cdocuments%5cvisual%20studio%202017%5cprojects%5cnorconsult%5cnorconsult%5cextensions%5cjsonhelpers.cs%3aline%2057%22%7d&p1=%7b%7d
what can able read exeption?
it's refering link:
which tells it's bad data, futher more.
msg%22%20%3a%20%22unable%20to%20process%20the%20type%20'anonymous%20type'%2c%20because%20it%20has%20no%20known%20mapping%20to%20the%20value%20layer.%20%20%20at%20system.data.entity.core.objects.elinq.expressionconverter.newarrayinittranslator.typedtranslate
which is
msg unable process type anonymous type because has no known mapping value layer.system.data.entity.core.objects.elinq.expressionconverter.newarrayinittranslator.typedtranslate(so on)
btw it's accii in url.
Comments
Post a Comment