I am creating a method that returns an HttpResponseMessage. I need to use a custom JSON Formatter, as shown below:
var jsonFormatter = new JsonMediaTypeFormatter();
jsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
jsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
IsoDateTimeConverter dateConverter = new IsoDateTimeConverter
{
DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff'Z'"
};
jsonFormatter.SerializerSettings.Converters.Add(dateConverter);
When I use Newtonsoft.Json version="10.0.2" or "10.0.1" and targetFramework="net461", I get the exception below:
Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()
If I downgrade to Newtonsoft.Json version="9.0.1", then it works fine. However, we would like to get some of the async support of version 10.
Is this a know bug? Is there a work around?
I had this issue when an old web.config on a server had a binding redirect to v8.0.0 even though v10.0.0 was present in the bin folder.
I changed:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
to:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
and the issue was resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With