Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EnterpriseLibrary 6 error: Cannot access a disposed object (Object name: 'Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter')

  • I have an ASP.NET MVC 5 application
  • The app uses Logging Application Block and Exception Application Block
  • In the production environment I found the following error message happening multiple times:

Cannot access a disposed object. Object name: 'Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter'. at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.ExecuteReadOperation(Action readOperation) at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.Write(LogEntry log) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.WriteToLog(String logMessage, IDictionary exceptionData) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler.HandleException(Exception exception, Guid handlingInstanceId) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.ExecuteHandlerChain(Exception ex, Guid handlingInstanceID)

The error seems to happen when there is an asynchronous request which fails on the server. When the server tries to handle this error, ExceptionHandling app block fails.

The problem I have is, of course, that I don't understand the reason for this error, but what bugles me the most is the fact that I cannot replicate the error.

I have tried re-initializing the AppDomain (via web.config), recycling the App pool, restarting the IIS server just before the ajax request is sent. I have also created a LogWriterWrapper singleton to set the LogWriter instance but the behavior is the same. From time to time, the error when trying to handle the exception still occurs.

I don't know if it could be related, but it seems this error only occurs when the client is ie8/ie9. It never occurred when chrome was used for example, but I guess this might be just by chance alone...

like image 433
Dragos Avatar asked Oct 14 '25 11:10

Dragos


1 Answers

In the end, for anyone who encounters this issue, in my case it was because in some parts of the application, there was another instantiation of the LogWriter

Logger.SetLogWriter(new LogWriterFactory().Create(), false);

Because I had some static helpers for logging and exception handling, where I initialized logwriter and also exceptionmanager, whenever an exception occurred durring the app use, which needed to be handled by the exceptionmanager, after the second manual instantiation has already ran, the exceptionamanger was still "hooked" on an instance of logwriter which was not present any more

like image 85
Dragos Avatar answered Oct 17 '25 01:10

Dragos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!