Asp.Net 5 Application is losing state when enters an Event Handler C-Sharp


Question: A C# Application is losing Application State e.g. IFeatureCollection, it says " System.ObjectDisposedException: IFeatureCollection has been Disposed. Object name : 'Collection'.


Login to See the Rest of the Answer

Answer:
If you experience this error it is because your code execution entered into an Event Handler hence losing the Application State. All Objects, Interfaces and Collections will be disposed because the Event Handler enters into a listening mode. The Event Handler will listen to an incoming data stream.

In order to solve this issue, if you want to get access to the Application Features, e.g. IFeatureCollection or the Database Context then consider calling a function that returns IActionResults. The call should originate from the Front-End, this way all Dependecies will be injected into a Dependecy Container and ready or available for Access again. If you want to store data from the previous request or from the logic in the Event Handler then cache the data you need (done in the Event Hanlder) then access the data from the Cache.

[NB] Keep in mind to clear the Cache before a new request or Register a CacheRepository as a Scopped in Service Container.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]