none
Hang on AppDomain.Unload() only on Windows 8.x (language OS i.e. german, japanese, etc) RRS feed

  • Question

  • We have unmanaged application which loads unmanaged DLLs whereas one of the DLL also loads a Mediator DLL which supports and loads managed code(C#).
    After launch of application, Mediator DLL initializes managed code and further managed code creates a AppDomain, loads  plugins and attempts to unload the AppDomain.
    The statement AppDomain.UnLoad() hangs on Language Windows 8.x OS (tested on German and Japanese).
    Below is the sample code
               RemoteClassLoader instanceloader = null;
                AppDomain LoaderAppDomain = null;
                 LoaderAppDomain = AppDomain.CreateDomain("Loader Domain");

               instanceloader = (RemoteClassLoader)LoaderAppDomain.CreateInstanceAndUnwrap(this.GetType().Assembly.FullName, typeof(RemoteClassLoader).ToString());
                 if (LoaderAppDomain != null)
                {
                       AppDomain.Unload(LoaderAppDomain);
                }

    Above code has been working since Windows XP in english as well as language OS but started to hang with Windows 8.x language OS (difference here is, we have moved to .net framework 4.5.1, no issues with 3.5 framework).

    On Analyzing the dump using WinDBG, there is a possibility of OS thread(whntnotifychangedirectoryfile)

    Following are the details of dump.
    0:000> !analyze -v
    *******************************************************************************
    *                                                                             *
    *                        Exception Analysis                                   *
    *                                                                             *
    *******************************************************************************

    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for <exe name>.exe - 
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for DOMXT.dll - 
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for omniORB413_vc10_rt.dll - 
    GetUrlPageData2 (WinHttp) failed: 12029.

    FAULTING_IP: 
    +ca03d1a6b0
    00000000`00000000 ??              ???

    EXCEPTION_RECORD:  ffffffffffffffff -- (.exr 0xffffffffffffffff)
    ExceptionAddress: 0000000000000000
       ExceptionCode: 80000007 (Wake debugger)
      ExceptionFlags: 00000000
    NumberParameters: 0

    CONTEXT:  0000000000000000 -- (.cxr 0x0;r)
    rax=00009bcdc4f389b2 rbx=0000000000000001 rcx=0000000000001004
    rdx=0000000000000001 rsi=0000000000000002 rdi=0000000000000002
    rip=0000000077c82772 rsp=000000000008ee08 rbp=000000000018d91c
     r8=0000000000000004  r9=0000000000000006 r10=0000000077bfb980
    r11=000000000018d978 r12=00000000fffdc000 r13=000000000008fdb0
    r14=000000000018d79c r15=0000000077c81f30
    iopl=0         nv up ei pl nz na po nc
    cs=0033  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200206
    wow64cpu!CpupSyscallStub+0x2:
    00000000`77c82772 c3              ret

    BUGCHECK_STR:  80000007

    DEFAULT_BUCKET_ID:  APPLICATION_HANG

    PROCESS_NAME:  <exe name>.exe

    ERROR_CODE: (NTSTATUS) 0x80000007 - {Kerneldebugger aktiviert}  Der Systemdebugger wurde von einem Interrupt aktiviert.

    EXCEPTION_CODE: (HRESULT) 0x80000007 (2147483655) - Vorgang abgebrochen

    NTGLOBALFLAG:  0

    APPLICATION_VERIFIER_FLAGS:  0

    APP:  quarkxpress.exe

    ANALYSIS_VERSION: 6.3.9600.17298 (debuggers(dbg).141024-1500) amd64fre

    MANAGED_STACK: !dumpstack -EE
    No export dumpstack found

    DERIVED_WAIT_CHAIN: 

    Dl Eid Cid     WaitType
    -- --- ------- --------------------------
       0   e20.790 Speculated (Triage)    -->
       1   e20.458 Idle Thread           

    WAIT_CHAIN_COMMAND:  ~0s;k;;~1s;k;;

    BLOCKING_THREAD:  0000000000000458

    PRIMARY_PROBLEM_CLASS:  APPLICATION_HANG

    LAST_CONTROL_TRANSFER:  from 0000000077bd73ff to 00007ffeb2eb757a

    FAULTING_THREAD:  0000000000000001

    STACK_TEXT:  
    00000000`0346e808 00000000`77bd73ff : 00000005`00000001 00000000`00000000 00000000`0346f0d0 00000000`0346e7b0 : ntdll!NtNotifyChangeDirectoryFile+0xa
    00000000`0346e810 00000000`77bcbb64 : 00000000`0512bef4 00000000`fffdb000 00000000`77bd738c 00000000`fffd9000 : wow64!whNtNotifyChangeDirectoryFile+0x73
    00000000`0346e880 00000000`77c821e5 : 00000023`77ccc14c 00000000`00000023 00000000`00000000 00000000`0512fff0 : wow64!Wow64SystemServiceEx+0xd4
    00000000`0346f130 00000000`77bd323a : 00000000`00000000 00000000`77c81503 00000000`00000000 00000000`77bd3420 : wow64cpu!ServiceNoTurbo+0xb
    00000000`0346f1e0 00000000`77bd317e : 00000000`00000000 00000000`00000000 00000000`0346fd30 00000000`0346f830 : wow64!RunCpuSimulation+0xa
    00000000`0346f230 00007ffe`b2e47004 : 00000000`00000000 00000000`00000000 00000000`fffdf000 00000000`00000000 : wow64!Wow64LdrpInitialize+0x172
    00000000`0346f770 00007ffe`b2e46eda : 00000000`0346f830 00000000`00000000 00000000`00000000 00000000`fffdf000 : ntdll!_LdrpInitialize+0xd8
    00000000`0346f7e0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!LdrInitializeThunk+0xe


    FOLLOWUP_IP: 
    wow64!whNtNotifyChangeDirectoryFile+73
    00000000`77bd73ff 4885ff          test    rdi,rdi

    SYMBOL_STACK_INDEX:  1

    SYMBOL_NAME:  wow64!whNtNotifyChangeDirectoryFile+73

    FOLLOWUP_NAME:  MachineOwner

    MODULE_NAME: wow64

    IMAGE_NAME:  wow64.dll

    DEBUG_FLR_IMAGE_TIMESTAMP:  5215f8c5

    STACK_COMMAND:  ~1s ; kb

    BUCKET_ID:  80000007_wow64!whNtNotifyChangeDirectoryFile+73

    FAILURE_BUCKET_ID:  APPLICATION_HANG_80000007_wow64.dll!whNtNotifyChangeDirectoryFile

    ANALYSIS_SOURCE:  UM

    FAILURE_ID_HASH_STRING:  um:application_hang_80000007_wow64.dll!whntnotifychangedirectoryfile

    FAILURE_ID_HASH:  {02742019-f52a-83db-ef20-8723a2174738}

    0:000> ~
    .  0  Id: e20.790 Suspend: 1 Teb: 00000000`fffdc000 Unfrozen
       1  Id: e20.458 Suspend: 1 Teb: 00000000`fffd9000 Unfrozen
       2  Id: e20.a18 Suspend: 1 Teb: 00000000`fffd6000 Unfrozen
       3  Id: e20.db4 Suspend: 1 Teb: 00000000`ffea4000 Unfrozen
       4  Id: e20.c38 Suspend: 1 Teb: 00000000`ffea1000 Unfrozen
       5  Id: e20.ab0 Suspend: 1 Teb: 00000000`ffe9e000 Unfrozen
       6  Id: e20.3f4 Suspend: 1 Teb: 00000000`ffe95000 Unfrozen
       7  Id: e20.ec0 Suspend: 1 Teb: 00000000`ffe92000 Unfrozen
       8  Id: e20.a54 Suspend: 1 Teb: 00000000`ffe8f000 Unfrozen
       9  Id: e20.9bc Suspend: 1 Teb: 00000000`ffe8c000 Unfrozen
      10  Id: e20.f4c Suspend: 1 Teb: 00000000`ffe89000 Unfrozen
      11  Id: e20.fd0 Suspend: 1 Teb: 00000000`ffe86000 Unfrozen
      12  Id: e20.5bc Suspend: 1 Teb: 00000000`ffe7d000 Unfrozen
      13  Id: e20.f1c Suspend: 1 Teb: 00000000`ffe7a000 Unfrozen
      14  Id: e20.bf0 Suspend: 1 Teb: 00000000`ffe77000 Unfrozen
      15  Id: e20.d3c Suspend: 1 Teb: 00000000`ffe74000 Unfrozen
      16  Id: e20.ff0 Suspend: 1 Teb: 00000000`ffead000 Unfrozen
      17  Id: e20.930 Suspend: 1 Teb: 00000000`ffeaa000 Unfrozen

    Followup: MachineOwner

    Did anybody face similar kind of issue ? I will appreciate inputs to analyze this issue.

    Previously posted on

    https://social.technet.microsoft.com/Forums/windows/en-US/d051e8d2-7ccc-473a-b1ed-d2621203feff/hang-on-appdomainunload-only-on-windows-8x-language-os-ie-german-japanese-etc?forum=w8itproappcompat



    • Edited by Mahesh Vyas Tuesday, January 20, 2015 9:09 AM renamed the executable name
    Monday, January 19, 2015 9:39 AM

All replies

  • Hello,

    >>Above code has been working since Windows XP in english as well as language OS but started to hang…

    If you mean, this works with XP with .NET Framework 3.5 and fails with windows 8.x and 4.5.1, my suggestion is that you could have a try to test with windows 8.x and 3.5 to see if it is caused by the OS or the new version Framework.

    According to this blog, please have a try to debug into the .Net source, in your case, you could check the interal logic implementation in the UnLoad method which might be helpful I think.

    Regards.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 20, 2015 8:14 AM
    Moderator
  • Hi Fred Bao,

    It works with 3.5 framework on OS 8.x (language OS).

    I tried with .net framework symbols and could debug in AppDomain.Unload() but probably symbols for AppDomain.nUnload() is not availlable.

    I also tried downloading source code of .net framework 4.5.1

    #if FEATURE_REMOTING
            [System.Security.SecuritySafeCritical]  // auto-generated
            [SecurityPermissionAttribute( SecurityAction.Demand, ControlAppDomain = true ),
             ReliabilityContract(Consistency.MayCorruptAppDomain, Cer.MayFail)]            
            public static void Unload(AppDomain domain)
            {
                if (domain == null)
                    throw new ArgumentNullException("domain");
                Contract.EndContractBlock();

                try {
                    Int32 domainID = AppDomain.GetIdForUnload(domain);
                    if (domainID==0)
                        throw new CannotUnloadAppDomainException();
                    AppDomain.nUnload(domainID); symbols not available
                }
                catch(Exception e) {
                    throw e;    // throw it again to reset stack trace
                }
            }
    #endif

    Thanks,

    Mahesh Vyas



    • Edited by Mahesh Vyas Tuesday, January 20, 2015 10:46 AM more information related to .net frameworks
    Tuesday, January 20, 2015 9:08 AM
  • Hello,

    That method seems to be an internal one which we cannot access it. Here is my suggestion for this issue, I notice in your original post you mentioned that it initializes managed code and creates the AppDomain from another application, you could have a try to create a pure managed application as a C# Console application to do the same thing to see if it still hangs, this would help narrow down this issue.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 21, 2015 9:33 AM
    Moderator
  • I could not reproduce it with sample app in any form.

    I have observed that if we show any dialog (e.g MessageBox) prior to this, surprisingly, then there is no Hang. 

    Wednesday, January 21, 2015 9:44 AM
  • Hello,

    >>I have observed that if we show any dialog (e.g MessageBox) prior to this, surprisingly, then there is no Hang.

    This sounds strange, I am wondering if it is because your unmanned code are trying to create dialog thread when calling the AppDomain.Unload() method, and this causes a deadlock, you could check this article which describes how to monitor the deadlock in .NET which might be helpful to find the caused reason:

    https://msdn.microsoft.com/en-us/magazine/cc163352.aspx

    Since if showing any dialog prior to this, it could work fine, you could find a way to make sure there is always any dialog prior to this call to UnLoad() method.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 22, 2015 11:07 AM
    Moderator
  • If you are using WPF, see a specific problem and workaround too: http://connect.microsoft.com/VisualStudio/feedbackdetail/view/798279

    Friday, January 23, 2015 9:37 AM