1

Recently I have faced with a very strange problem. My Action method must return JsonResult,and all is good untill the last break point before return (At this moment I have correct json result).Then in browser console I see error 500 (Internal server error).Nothing exception in debugger.When I start to chek every step in debugger with F10,F11 I have noticed something strange.Unexpected infinitive invokes to my model properties (sometimes to model properties,sometimes infinitive invoking functions and then model proerties).I decide that this infinitive loop provoked error (but I still misunderstanding why I couldn't see it in debugger - perhaps this is aspect of IIS debugging).Code hasnt got weak places (I dont show it because it will take much more than few space).I know that my question is not constructive in stackoverflow terminalogy but I hope that somebody has encountered the same problem.I need only ideas.Thanks.

SOLUTION

As noticed @mreyeros and @ LastCoder self referencing can be the reason of such behavior.I have cheked my model in details and found this place:

    private IEnumerable<CollegeEstimateModel> _initialModels;

    public IEnumerable<CollegeEstimateModel> InitialModels
    {
        get { return _initialModels = _initialModels ?? CreateInitialModelsList(); }
    }

where CollegeEstimateModel contains above properties

I have added [ScriptIgnore] attribute and all become ok.

pnuts
  • 58,317
  • 11
  • 87
  • 139
user2586558
  • 59
  • 1
  • 6
  • maybe your model(s) has nested circular references that are causing the conversion to Json to loop infinitely until it errors out. If this is the case you need to flatten your object(s) before using the Json() method. – Louis Ricci Jul 29 '13 at 17:24

1 Answers1

1

You should start by checking to see if the model that you are trying to serialize to your JSON result does not contain a property with a self referencing property. For example you have an Order object that contains a collection of details. The detail record has a navigation property back up to the parent order, thus causing a loop during serialization of the order object. This is just a guess of course, but hope that it helps

mreyeros
  • 4,359
  • 20
  • 24