AppDomain unload fails on Windows 10


(Elisée Houede) #1

Hello Guys.

We have been using Hydra for a couple of years now and accomplished quite few “interesting” things with it. :wink:
Our main application is in Delphi 7 and our plugins in .Net 4.0
Unfortunately, we have accountered a blocking issue since our customers upgraded to Windows 10: our application takes a very long time to close and we get the following exception message: OLE error 80131015.
After investigating, it seems that the problem occurs on unloading module.
We managed to fix the problem by not creating a new appdomain when loading the module: Loadmodule(moduleX, False).
But not creating new appdomain does not suit us for a lot of reasons. We need to really keep our plugins separated from the main application.
Here are our questions:

  • Are you aware of such a problem?

  • Do you guys have any idea why unloading fails and takes that much time?

  • How can we manage to keep AppDomain creation when loading modules?

Thanks in advance for your answers. We are quite in a struggle right now.

Best Regards

(antonk) #2


We’ve just tried a set of testcases on Win10 and there were no exceptions. As social.msdn says

This type of exception does happen when you are stuck inside unmanaged code which performs an uninterruptable blocking operation. Waiting for a native socket select would be such a case. If your Dll does cause socket connections make sure you close them before they your unload your AppDomain.

There is also an advice on finding the exact cause of the error:

You could hook the AppDomain.Unload Event and throw an exception from there, or use System.Diagnostics.Debug.Assert(false) to trigger the debugger. When you attach make sure you select managed and native debugging enabled. Now you can selected in the Debug->Windows the Threads window and check the call stack where each thread is standing by checking the Call Stack window. This could help to find out why the AppDomain cannot be unloaded.

The discussion itself can be found at

Hope that helps

(Rohit Bajaj) #3

We are having similar issue in the Windows 10 environment, our application randomly crashes (somewhere between the OnBeforeUnloadModule and OnAfterUnloadModule events) when we attempt to unload the plugin. If we don’t load each module in a separate AppDomain, everything seems to works fine!

(ksinlin) #4

Is there any other solution without create new app domain ? because it happens the same case in our application in customer Windows 10 (cannot reproduce in development environment that’s the big issue). @Elisée , if you have a possible solution please share with me.

Thanks in advance.

(Rohit Bajaj) #5

Do you have single instance of HydraModuleManager?

(ksinlin) #6

Yes. We use HYModuleManager to load managed module with separate app domain and create visual plugin.

(Rohit Bajaj) #7

In Windows 10 enviroment, this error only occurs when the OnAfterUnloadModule event doesn’t fire and when this event does fire correctly; there is no error.
Loading modules in shared AppDomain (rather than separate AppDomain) triggers the event to fire everytime.