Web API c#.net Response 500 null reference json serialization

SDNADEV 1 Reputation point
2021-06-12T11:04:23.607+00:00

Hi Team,

We are using web APIs in our project, The time we access first web API from our project we get a 500 error as a response. once we restart the app pool on the machine, the error goes away and everything works fine.

It occurs very rarely. So, it's very hard to reproduce. error is invoked on its own

As per our current investigation, we noted once in our local machine while debugging found the attached exception.

We get a null reference exception while serializing objects to JSON. check attachment for info

The issue occurs very rarely on both server(Windows Server 2019) and local window machine
.net framework version being used with this mvc c#.net webapi is 4.5.1

Following things we have tried : -

  1. Upgraded the json version to Newtonsoft.json.13.0.1
  2. Update the response to a mvc model from as earlier we were sending entity
  3. Globally we have setup the below line in webapiconfig file
    config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,409 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Duane Arnold 3,216 Reputation points
    2021-06-12T16:02:05.623+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.