Error in Event Viewer when terminating the MVC application and resource Dispose Microsoft.Practices.Unity.Mvc

0

How to fix this error? Error happened when MVC app Shutdown by ldle Time-out. It occurs in the method Shutdown from library Microsoft.Practices.Unity.Mvc If the shutdown method is comment out, the error does not occur. But then, I guess, resources are not cleaned up. I would like to error occurred, and resources to clean up. Help, please.

Error In the event viewer:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Error" /> 
  <EventID Qualifiers="0">1000</EventID> 
  <Level>2</Level> 
  <Task>100</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2017-07-24T09:22:08.000000000Z" /> 
  <EventRecordID>12394</EventRecordID> 
  <Channel>Application</Channel> 
  <Computer>name</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>w3wp.exe</Data> 
  <Data>8.5.9600.16384</Data> 
  <Data>5215df96</Data> 
  <Data>clr.dll</Data> 
  <Data>4.6.1087.0</Data> 
  <Data>583e5e56</Data> 
  <Data>c00000fd</Data> 
  <Data>000000000000b23a</Data> 
  <Data>a70</Data> 
  <Data>01d3045e0a63e3f7</Data> 
  <Data>c:\windows\system32\inet\w3wp.exe</Data> 
  <Data>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll</Data> 
  <Data>908f1a25-7051-11e7-80e7-005056a1519e</Data> 
  <Data /> 
  <Data /> 
  </EventData>
  </Event>

WindowsLog – System - warning A process serving application pool ' PoolName ' terminated unexpectedly. The process id was '2672'. The process exit code was '0xc00000fd'.

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Microsoft-Windows-WAS" Guid="{524B5D04-133C-4A62-8362-64E8EDB9CE40}" EventSourceName="WAS" /> 
  <EventID Qualifiers="32768">5009</EventID> 
  <Version>0</Version> 
  <Level>3</Level> 
  <Task>0</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2017-07-24T09:22:22.000000000Z" /> 
  <EventRecordID>38904</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="0" ThreadID="0" /> 
  <Channel>System</Channel> 
  <Computer>name</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data Name="AppPoolID">PoolName</Data> 
  <Data Name="ProcessID">2672</Data> 
  <Data Name="ExitCode">c00000fd</Data> 
  </EventData>
  </Event>

Code file, that if to comment out a way to disable this error does not occur

using System.Linq;
using System.Web.Mvc;
using Microsoft.Practices.Unity.Mvc;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(SpecificationSap.App_Start.UnityWebActivator), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(SpecificationSap.App_Start.UnityWebActivator), "Shutdown")]

namespace SpecificationSap.App_Start
{
    /// <summary>Provides the bootstrapping for integrating Unity with ASP.NET MVC.</summary>
    public static class UnityWebActivator
    {
        /// <summary>Integrates Unity when the application starts.</summary>
        public static void Start() 
        {
            var container = UnityConfig.GetConfiguredContainer();

            FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
            FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            // TODO: Uncomment if you want to use PerRequestLifetimeManager
            // Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
        }

        /// <summary>Disposes the Unity container when the application is shut down.</summary>
        public static void Shutdown()
        {
            var container = UnityConfig.GetConfiguredContainer();
            container.Dispose();
        }
    }
} 
c#
events
model-view-controller
nuget
asked on Stack Overflow Jul 24, 2017 by katerinkadar • edited Aug 4, 2017 by Liam

1 Answer

0

Answer posted in question by OP. I've moved into an answer below:

When I started the application in debug mode I saw the error:

System.StackOverflowException was unhandled Message: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

The cause of the stackoverflow is infinite recursive call to Dispose of UnityContainer, which I think is (weirdly) caused by the automatically registered IUnityContainer which is not managed by our code and should be handled in unity library. I was able to stop the infinite recursion simply by swapping out the usage of the UnityContainer class with a derived class that override Dispose and returns on a recursive call:

public class CustomUnityContainer : UnityContainer
{

    private bool inDispose = false;

    protected override void Dispose(bool disposing)
    {
        if (inDispose) //prevents recursive calls into Dispose
            return;

        inDispose = true;

        base.Dispose(disposing);

        inDispose = false;

    }
}

Total, I hope I have correctly solved this problem. If you have any comments and suggestions, please share, because the question for me still open and not the fact that I correctly solved the problem.

answered on Stack Overflow Aug 4, 2017 by Liam

User contributions licensed under CC BY-SA 3.0