This project has moved and is read-only. For the latest updates, please go here.

UnsafeIISMethods and MgdHasConfigChanged

Jan 15, 2014 at 2:47 PM
Hi,

in file UnsafeIISMethods.cs you are getting a method from '"System.Web.Hosting.UnsafeIISMethods' called 'MgdHasConfigChanged', but mine DLL does not contain this method, more the 'webengine4.dll' does not contain it either.

This method is a part of some future .NET update or I'm missing something? I would really like to use this feature to detect Shutdowns like in ShutdownDetector.
Jan 16, 2014 at 10:21 PM
What versions of .NET and Windows are you using?
Apr 24, 2014 at 6:56 AM
I've encountered the same issue. I'm running Windows 8.0 Pro, .NET 4.5.1. System.Web.dll is v4.0.0.0. File version is 4.0.30319.18447.
Apr 24, 2014 at 5:05 PM
Ah. That private API was replaced with a public one in .NET 4.5.1. Katana was also updated to use the public API where available. What version of Katana are you using?
Apr 25, 2014 at 12:40 AM
Funnily enough I'm not using Katana, but was directed to its ShutdownDetector class as a way to detect a pending AppDomain shutdown. I was directed to an old version though, which didn't allow for the .NET 4.5.1 update you mention, and instead depended solely on MgdHasConfigChanged.

I'd originally intended to rely on the IRegisteredObject pattern for detecting shutdowns, but discovered that the Stop method on that won't get called if there are any outstanding requests. This can be a big problem if those requests are long-running, or perpetually kept alive (e.g. SignalR), because the AppDomain may shutdown without a single IRegisteredObject.Stop method ever being called.

The HostingEnvironment.StopListening event (being used in the latest version of ShutdownDetector) looks like exactly what I need though, and I don't even need to use reflection to get at it. MSDN describes it:
"Applications that use long-running requests, for example SignalR applications, can listen for the StopListening event and gracefully shut down their long-running operations when IIS has initiated the shutdown of an application pool and its associated worker processes."

Perfect :)