I have a Web Project setup that has both my WebForms and a WCF service. I am having an issue where every so often my application seems to recycle and i lose all singleton objects and session values. It does not appear to be a timeout issue, but maybe a memory leak of some kind. We can be using the app for a minute or so and then bam it just loses everything.
I have tried monitoring the directory for changes but found no changes to the filesystem at all. I also put a breakpoint in Application_Error and there are no errors being thrown.
I have been googling for two days trying to resolve this issue. The application is a direct duplication of a previous project that is working fine. The one thing I noticed that is different is my last project I used nHibernate for the backend and this project I switched to using Linq to SQL. I noticed that I wasn't handling the DataContext properly because I was diming an isntance of the DataContext inside my service calls and returnin开发者_StackOverflowg a value before ever disposing or setting the context back to nothing, so I figured it may not be closing. I tried instead of storing the datacontext in my "repository" class i stored it inside the operationcontext and explicitly dispose it on Application_EndRequest. That still hasn't resolved the issue.
Anyone have any suggestions or places I should look?
** UPDATE **: I believe i found my issue. I have objects that are using EntitySet and i am serializing those objects directly back using a serializable IList property with a linq query returning the list. When i tried to explicitly dispose of my datacontext before returning the data I am running into issues serializing those EntitySet's now because the datacontext is no longer active. I am going to try copying the data into a new blank object with regular Lists instead of EntitySet's and see if this will allow me to properly close my datacontext and resolve my issue.
Update is really a different question, but you really should not try and serialize stuff that comes off of an ORM -- lots of potential nightmares. Build yourself some DTOs.
In the IIS7 Console, select the specific application pool, and select "Recycling..." in the action pane to the left. It's a wizard that lets you define how the application pool recycles, and how it logs the recycle events to the event log (page 2 of the wizard).
精彩评论