Last post Apr 13, 2016 10:03 AM by rahulkishore
Mar 03, 2016 07:15 AM|amitkekan|LINK
I need some help as i am stuck in a weird problem.
I have a WebApi 2.0 that's exposes methods which fetch the data from SQL server using Entity framework via Unity Controller. The Database layer is part of an application that populates the data to the SQL server database. Hence i am only performing get operations
through the WebAPi.
I am getting a "object reference..." exceptions in few of my WebApi methods randomly for fetching the same data. The WebApi is hosted on Azure Worker Role. It's as self hosted WebApi using OWIN. The error goes away if i restart the worker role, but comes
back gain after few hours. I have tried adding null checks at various locations in my code. But every time the error popups up at some different place.
I have tried taking the backup of the Database and test from my local machine but the issue does not repro.
Can some one please guide me in debugging this?
Mar 04, 2016 10:25 AM|Yohann Lu|LINK
As far as I know, Typically, this error is caused by Reference object's value is NULL.
So, I suggest you check your code. You need to discover which objects cause the abnormalities. Then analyze the object in your application throughout the life cycle. You could add null checks in each place may cause the error.
Mar 07, 2016 09:42 AM|amitkekan|LINK
But adding null checks does not solve my problem. I have already tried that and ended up with errors thrown at different places inside third party libraries.
The issue is that if i restart the worker role, then while accessing the same data the code works. But it stops working after few hours (when number of hits to WebApi increases).
Not sure but it seems that somewhere there seems to be a memory issue due to which object instances are lost.
Still looking for answer.... :(
Mar 16, 2016 10:22 AM|Yohann Lu|LINK
The object created from the Entity Model will hold all objects(all kinds of information lifecycle). So, It can come very big, then the ram memory can come very high. I suggest you can try the following methods.
1: Enhance memory configuration
2: Optimizing Data Storage
3: Timely destruction invalid data
Information about Entity Framework Object Context Life Cycle compared to Linq to Sql Data Context Life Cycle for your reference:
Also, you can visit the Azure forums to get more information.
Azure and ASP.NET:
Apr 13, 2016 10:03 AM|rahulkishore|LINK
Hi, this may be a bit late buy maybe I can help.
I've ran into these issues before in web api. Go and put break points where you're fetching the data from the Db. See what's exactly being returned. More of then than not there's an exception being returned because of an incorrect mapping or the number of
fields being returned doesn't match the data type. Doubt it would be a memory loss issue, usually object reference errors are because you're trying to use an object that was supposed to be populated before hand.
Let me know if you can figure this out.