Home > other >  As the JSON serialization IHttpActionResult cause an exception
As the JSON serialization IHttpActionResult cause an exception

Time:04-10


I have a small Web API 2 applications, I tried to realize the incoming requests and outgoing response of logging (basically records you see things through HTTP traffic Fiddler2),
In an attempt to serialize a response from a method, I received, I don't know how to handle the exception, I try to play JsonSerializerSettings etc, I might be completely wrong way to do it, would appreciate any guidance,
Below is a lead to abnormal code snippet,
Var response=Ok (successMessage);
JsonSerializerSettings Settings=new JsonSerializerSettings
{
PreserveReferencesHandling=Newtonsoft. Json. PreserveReferencesHandling Objects,
ReferenceLoopHandling=ReferenceLoopHandling. Ignore
};
This. Logging. LogMessage (MessageType. ServiceResponse, JsonConvert SerializeObject (response, Formatting. Indented, Settings));
return response;

Exception:
Newtonsoft. Json. JsonSerializationException: Error getting value from 'ReadTimeout' on 'System. Web. HttpInputStream. - & gt;
System. InvalidOperationException: Timeouts are not supported on this stream. The ats System. IO. Stream. Get_ReadTimeout () at GetReadTimeout (Object)
The at Newtonsoft. Json. Serialization. DynamicValueProvider. GetValue (Object target) - End of inner exception stack trace -- -- --
The at Newtonsoft. Json. Serialization. DynamicValueProvider. GetValue (Object target)







CodePudding user response:


Is there a response within 1 a one-to-many relationship? In the response contains a list, and it contains in the list item back in response to a reference?
When constructing a json child nodes, unable to refer to their parent node, in attempt to serialize an infinite loop,
Build a view model and the reference to the parent, as long as through the parentid,

CodePudding user response:

Problem solved, I also encountered similar problems, to solve
  • Related