NullReferenceException even though setting value while returning JSON

Viewed 49

In the results Im getting null value, getting NullReferenceException when the return is happening. I have used nullcheck yet I'm getting the error

results = //Here one get call is happening and the value is null
 return Json(new
 {
   HasPermission = hasPermission,
   EmployeeCount = results == null? 0 : results.Count,
 });
1 Answers

I think your code has problem in Json() what is this method do? Could you check it?? *The below code is compiled successfully in VSCode

The below code is compiled successfully in VSCode

I even tried using System.Text.Json.JsonSerializer.Serialize still not error.

enter image description here

Related