c# - JsonMediaTypeFormatter formatting with k__backingfield -


i'm having issue jsonmediatypeformatter far can tell started happening recently.

at point, object have (a plain old poco) started serializing complete backing fields. using auto properties (again poco) whatever reason output jsonmediatypeformatter k__backingfield<propname>:"value"

in last weeks have upgraded visual studio 2015 (though doubt root cause of problem, has been working few weeks prior).

i have cleared forms of nuget caches, deleted bin/obj directories.... uninstalled , reinstalled visual studio 2015 professional... repaired visual studio 2015 professional.... code hasn't changed in time.

we using version 5.2.0 of system.net.http.formatting.

thank help.

just quick update.... not happening on else's machine. not experiencing errors (that noticing). i'm going add visual studio 2015 related tags well

ok quick update. have sent linqpad script assemblies required run script co-worker. assemblies sending exact ones have pulled nuget , compiled on machine. when runs code, serializes desired. machine (and co-worker's machine) experiencing issue still.

i'm continuing isolate as possible further guidance appreciated

i can work around issue turning jsonmediatypeformatter.usedatacontractjsonserializer property true. i'm doing more research why works , why want or not want this... i'll have run more tests in morning co-workers not having problem. don't idea of code change fixing behaving unpredictably.

ok! 1 more update. far machines affected have installed active reports 10. performing more tests , going install active reports 10 on machine not affected see if indeed culprit. adding tag active reports. open bug them if ends being true.

are pocos marked [serializable] attribute? if so, may cause of issue.

web api apparently ships json.net defaultcontractresolver configured ignoreserializableattribute = false. 1 of effects of setting names of auto properties serialized in format <propertyname>k__backingfield propertyname replaced actual name of property.

to fix this, can either remove [serializable] attribute classes, or can replace out-of-box resolver new 1 has ignoreserializableattribute = true. latter, add following application_start method in global.asax:

var resolver = new newtonsoft.json.serialization.defaultcontractresolver(); resolver.ignoreserializableattribute = true; var config = globalconfiguration.configuration;     config.formatters.jsonformatter.serializersettings.contractresolver = resolver; 

here fiddle demonstrates concept (although console app, not web api): https://dotnetfiddle.net/bu6lgy


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -