问:
.Net app deadlock and GC
I'm working on a .net system, which under some special conditions (.net 2.20 AND .net 4.0 installed) generates a deadlock in one of (win) services. Using WinDbg i could find out that:

In thread 7:

```<code>0:007> !clrstack
OS Thread Id: 0xfec (7)
ESP       EIP
03c9dbd8 7c90e514 [HelperMethodFrame_PROTECTOBJ: 03c9dbd8] System.Reflection.Assembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
03c9dc70 79400e07 System.Reflection.Assembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
03c9dc90 7935c5e0 System.Reflection.Assembly.InternalLoad(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean)
03c9dcb8 7939b788 System.Reflection.Assembly.InternalLoadFrom(System.String, System.Security.Policy.Evidence, Byte[], System.Configuration.Assemblies.AssemblyHashAlgorithm, Boolean, System.Threading.StackCrawlMark ByRef)
03c9dcdc 7939b725 System.Reflection.Assembly.LoadFrom(System.String, System.Security.Policy.Evidence)
03c9dce4 79398fdb System.Activator.CreateInstanceFrom(System.String, System.String, Boolean, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Security.Policy.Evidence)
03c9dd10 79399653 System.AppDomain.CreateInstanceFrom(System.String, System.String)
03c9dd1c 793b8e39 System.AppDomain.CreateInstanceFromAndUnwrap(System.String, System.String)
03c9df48 79e7c0e3 [GCFrame: 03c9df48]
03c9df64 79e7c0e3 [GCFrame: 03c9df64]
03c9e0d4 79e7c0e3 [ContextTransitionFrame: 03c9e0d4]
03c9e1d8 79e7c0e3 [GCFrame: 03c9e1d8]
03c9e1bc 79e7c0e3 [GCFrame: 03c9e1bc]
03c9f43c 79e7c0e3 [CustomGCFrame: 03c9f43c]
03c9f450 79e7c0e3 [CustomGCFrame: 03c9f450]
03c9f464 79e7c0e3 [CustomGCFrame: 03c9f464]
03c9f478 79e7c0e3 [CustomGCFrame: 03c9f478]
03c9f48c 79e7c0e3 [CustomGCFrame: 03c9f48c]
03c9f4a0 79e7c0e3 [CustomGCFrame: 03c9f4a0]
03c9f4b4 79e7c0e3 [CustomGCFrame: 03c9f4b4]
03c9f880 79e7c0e3 [TPMethodFrame: 03c9f880] System.AppDomain.CreateInstanceFromAndUnwrap(System.String, System.String)
03c9f894 00a64498 Roche.RIG.CLink.DomainObject.Create[[System.__Canon, mscorlib]](System.String, Roche.RIG.CLink.CoreSystem.Interfaces.IBaseCoreSystem, Roche.RIG.CLink.TypeLifeManagementAction)
03c9f8dc 00acf220 Roche.RIG.SmartCom.DomainMgr.Load[[System.__Canon, mscorlib]](System.String)
03c9f92c 00acf075 Roche.RIG.SmartCom.DomainMgr.GetTunnel()
03c9f968 00acef05 Roche.RIG.SmartCom.CoreSystem.StartupTunnel(System.Object)
03c9f9b4 793e25cf System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(System.Object)
03c9f9bc 79366b3d System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
03c9f9d4 793e2734 System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback)
03c9f9e8 793e26ac System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(System.Object)
03c9fb78 79e7c0e3 [GCFrame: 03c9fb78]
</code>```

and in the other thread (thread 3):

```<code>0:003> !clrstack
OS Thread Id: 0xb08 (3)
ESP       EIP
00d4eac4 7c90e514 [GCFrame: 00d4eac4]
00d4faa4 7c90e514 [PrestubMethodFrame: 00d4faa4] Roche.RIG.SmartCom.CoreSystem.StartupTasks(System.Object)
00d4fab4 793e25cf System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(System.Object)
00d4fabc 79366b3d System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
00d4fad4 793e2734 System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback)
00d4fae8 793e26ac System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(System.Object)
00d4fc78 79e7c0e3 [GCFrame: 00d4fc78]
</code>```

Output of !locks

```<code>0:007> !locks

CritSec +157d20 at 00157d20
LockCount          1
RecursionCount     1
OwningThread       fec
EntryCount         1
ContentionCount    1
*** Locked

CritSec wininet!GlobalCacheCritSect+0 at 7723ba38
LockCount          4
RecursionCount     4
OwningThread       b08
EntryCount         1
ContentionCount    1
*** Locked

CritSec +1a1310 at 001a1310
LockCount          0
RecursionCount     1
OwningThread       b08
EntryCount         0
ContentionCount    0
*** Locked

Scanned 1212 critical sections
</code>```

Output of syncblk

```<code>0:003> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
-----------------------------
Total           370
CCW             1
RCW             319
ComClassFactory 0
Free            0
</code>```

Output of ~*kv 90

```<code>    0:007> ~*kv 90

       0  Id: ebc.edc Suspend: 1 Teb: 7ffdd000 Unfrozen
    ChildEBP RetAddr  Args to Child
    0012f090 7c90d9da 7c801879 000001a4 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    0012f094 7c801879 000001a4 00000000 00000000 ntdll!NtReadFile+0xc (FPO: [9,0,0])
    0012f0fc 77df348b 000001a4 0012f1c8 00000216 kernel32!ReadFile+0x16c (FPO: [Non-Fpo])
    0012f128 77df331f 000001a4 0012f1c8 00000216 advapi32!ScGetPipeInput+0x2a (FPO: [Non-Fpo])
    0012f19c 77df3628 000001a4 0012f1c8 00000216 advapi32!ScDispatcherLoop+0x3f (FPO: [Non-Fpo])
    0012f3fc 006ea31e 0019c3f8 a82bfd52 00000000 advapi32!StartServiceCtrlDispatcherW+0xe3 (FPO: [Non-Fpo])
    *** WARNING: Unable to verify checksum for System.ServiceProcess.ni.dll
    WARNING: Frame IP not in any known module. Following frames may be wrong.
    0012f418 67a241d2 0106174c 01061ab0 0019c400 0x6ea31e
    00000000 00000000 00000000 00000000 00000000 System_ServiceProcess_ni+0x41d2

       1  Id: ebc.d1c Suspend: 1 Teb: 7ffdc000 Unfrozen
    ChildEBP RetAddr  Args to Child
    0082fe38 7c90df4a 7c809590 00000003 0082fe64 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    0082fe3c 7c809590 00000003 0082fe64 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
    0082fed8 7c80a115 00000003 0082ff1c 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
    0082fef4 79ed25eb 00000003 0082ff1c 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
    0082ff54 79ed2548 a8b35c0c 00000000 79ece48c mscorwks!DebuggerRCThread::MainLoop+0xe9 (FPO: [Non-Fpo])
    0082ff84 79ed2477 a8b35c3c 79eb4145 79ece48c mscorwks!DebuggerRCThread::ThreadProc+0xe5 (FPO: [Non-Fpo])
    0082ffb4 7c80b729 00000000 79eb4145 79ece48c mscorwks!DebuggerRCThread::ThreadProcStatic+0x9c (FPO: [Non-Fpo])
    0082ffec 00000000 79ed2431 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

       2  Id: ebc.104 Suspend: 1 Teb: 7ffdb000 Unfrozen
    ChildEBP RetAddr  Args to Child
    009ffcd0 7c90df4a 7c809590 00000002 009ffcfc ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    009ffcd4 7c809590 00000002 009ffcfc 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
    009ffd70 7c80a115 00000002 7a3b9248 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
    009ffd8c 79e719ab 00000002 7a3b9248 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
    009ffdac 79ef8cd9 0016e5d0 009ffeb0 0016edc8 mscorwks!WKS::WaitForFinalizerEvent+0x77 (FPO: [Non-Fpo])
    009ffdc0 79ebab37 009ffeb0 00000000 00000000 mscorwks!WKS::GCHeap::FinalizerThreadWorker+0x79 (FPO: [Non-Fpo])
    009ffdd4 79ebaad3 009ffeb0 009ffe5c 79f495f5 mscorwks!Thread::DoADCallBack+0x32a (FPO: [Non-Fpo])
    009ffe68 79eba9f7 009ffeb0 a8ae5d2c 00000000 mscorwks!Thread::ShouldChangeAbortToUnload+0xe3 (FPO: [Non-Fpo])
    009ffea4 79ebbe48 009ffeb0 00000000 00158500 mscorwks!Thread::ShouldChangeAbortToUnload+0x30a (FPO: [Non-Fpo])
    009ffecc 79ebbe12 79ef8c6c 00000008 009fff14 mscorwks!ManagedThreadBase_NoADTransition+0x32 (FPO: [Non-Fpo])
    009ffedc 79ebb42b 79ef8c6c a8ae5c9c 00000000 mscorwks!ManagedThreadBase::FinalizerBase+0xd (FPO: [Non-Fpo])
    009fff14 79ebaf8e 00000000 8706da80 804fb078 mscorwks!WKS::GCHeap::FinalizerThreadStart+0xbb (FPO: [Non-Fpo])
    009fffb4 7c80b729 0016edc8 00730074 00610020 mscorwks!Thread::intermediateThreadProc+0x49 (FPO: [Non-Fpo])
    009fffec 00000000 79ebaf48 0016edc8 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

       3  Id: ebc.b08 Suspend: 1 Teb: 7ffd9000 Unfrozen
    ChildEBP RetAddr  Args to Child
    00d4d7a0 7c90df5a 7c91b24b 00000610 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    00d4d7a4 7c91b24b 00000610 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
    00d4d82c 7c901046 00157d20 7a08a990 00157d20 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
    00d4d834 7a08a990 00157d20 79e83b8f 00157d20 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
    00d4d83c 79e83b8f 00157d20 a8e57bf0 001dac60 mscorwks!UnsafeEEEnterCriticalSection+0x18 (FPO: [1,0,0])
    00d4d878 79e75c62 00d4d88c 79e75c56 00157d20 mscorwks!CrstBase::Enter+0x13c (FPO: [Non-Fpo])
    00d4d880 79e75c56 00157d20 00d4d89c 79e75c4a mscorwks!EEEnterCriticalSection+0xb (FPO: [Non-Fpo])
    00d4d88c 79e75c4a 7a3c38b0 00157d20 00d4df10 mscorwks!CExecutionEngine::AcquireLock+0xb (FPO: [Non-Fpo])
    00d4d89c 79eec124 00157d20 8000000a 7a195ccc mscorwks!ClrEnterCriticalSection+0x11 (FPO: [Non-Fpo])
    00d4d8a8 7a195ccc a8e57c98 0385d008 8000000a mscorwks!CCriticalSection::Lock+0x17 (FPO: [0,0,4])
    00d4df10 7a196399 00000001 00000001 80070002 mscorwks!CDebugLog::DumpDebugLog+0x5b (FPO: [Non-Fpo])
    00d4df24 7a17d78f 001dac60 00000001 00000001 mscorwks!CDebugLog::Flush+0x53 (FPO: [Non-Fpo])
    00d4df94 79ef3441 03858a40 79eef384 00000000 mscorwks!CAssemblyName::BindToObject+0x674 (FPO: [Non-Fpo])
    00d4e00c 79ef3261 00173918 00d4dfe0 03858a30 mscorwks!FusionBind::RemoteLoad+0x14d (FPO: [Non-Fpo])
    00d4e094 79ef3078 00173918 00179dd0 00d4e464 mscorwks!FusionBind::LoadAssembly+0x127 (FPO: [Non-Fpo])
    00d4e340 79ef0503 00158500 00000001 00d4e464 mscorwks!AssemblySpec::FindAssemblyFile+0xdc (FPO: [Non-Fpo])
    00d4e4ac 79ee1a9a 00d4e4d4 00000001 00000000 mscorwks!AppDomain::BindAssemblySpec+0x18d (FPO: [Non-Fpo])

00d4e544 79ee1958 23000010 00000000 a8e5466c mscorwks!PEFile::LoadAssembly+0x95 (FPO: [Non-Fpo])
00d4e5e4 79f07846 00158500 23000010 a8e545a8 mscorwks!Module::LoadAssembly+0xee (FPO: [Non-Fpo])
00d4e620 79ef70d9 006f4c1c 010000a3 00000000 mscorwks!Assembly::FindModuleByTypeRef+0x113 (FPO: [Non-Fpo])
00d4e670 79e82979 00d4e704 00000000 00000000 mscorwks!ClassLoader::LoadTypeDefOrRefThrowing+0xfc (FPO: [Non-Fpo])
00d4e6a0 79e9ecb3 00d4e704 006f4c1c 010000a3 mscorwks!ClassLoader::LoadTypeDefOrRefOrSpecThrowing+0xa0 (FPO: [Non-Fpo])
00d4e734 79e9bab0 006f4c1c 0a000148 00d4e9c4 mscorwks!MemberLoader::GetDescFromMemberDefOrRefThrowing+0x210 (FPO: [Non-Fpo])
00d4e9bc 79efa4a9 00000001 0a000148 00d4eb08 mscorwks!MemberLoader::GetMethodDescFromMemberDefOrRefOrSpecThrowing+0x219 (FPO: [Non-Fpo])
00d4ea48 79efaf4b 006f4c1c 0a000148 00d4eb40 mscorwks!MemberLoader::GetMethodDescFromMemberDefOrRefOrSpecNT+0x76 (FPO: [Non-Fpo])
00d4eb50 79efae1f 006f4c1c 0a000148 006f5718 mscorwks!CEEInfo::findMethodInternal+0x154 (FPO: [Non-Fpo])
00d4ebd0 79061fd6 00d4f5bc 006f4c1c 8a000101 mscorwks!CEEInfo::findMethod+0x107 (FPO: [Non-Fpo])
00d4ebe8 7906535a 8a000148 006f4c1c 006f5718 mscorjit!Compiler::eeFindMethod+0x22 (FPO: [Non-Fpo])
00d4ecb8 79063324 00000028 0a000148 baadbeef mscorjit!Compiler::impImportCall+0xa7 (FPO: [Non-Fpo])
00d4f290 790635c3 00b52c70 807e6cc2 00b53250 mscorjit!Compiler::impImportBlockCode+0x29ae (FPO: [Non-Fpo])
00d4f314 7906355b 00b52c70 00000000 00b50010 mscorjit!Compiler::impImportBlock+0x20c (FPO: [Non-Fpo])
00d4f32c 79063494 00b52bb8 00b50010 79064e1c mscorjit!Compiler::impImport+0xe5 (FPO: [Non-Fpo])
00d4f338 79064e1c 00b50010 00d4f39c 790614e6 mscorjit!Compiler::fgImport+0x20 (FPO: [0,0,4])
00d4f344 790614e6 00d4f464 00d4f6c8 00d4f458 mscorjit!Compiler::compCompile+0xb (FPO: [Non-Fpo])
00d4f39c 79061236 006f4c1c 00d4f5b0 00d4f63c mscorjit!Compiler::compCompile+0x2df (FPO: [Non-Fpo])
00d4f430 7906118c 00d4f5b0 00d4f63c 00d4f464 mscorjit!jitNativeCode+0xb8 (FPO: [Non-Fpo])
00d4f468 79efd49f 790b22a0 00d4f5b0 00d4f63c mscorjit!CILJit::compileMethod+0x3d (FPO: [Non-Fpo])
00d4f4d4 79efd415 00191950 00d4f5b0 00d4f63c mscorwks!invokeCompileMethodHelper+0x72 (FPO: [Non-Fpo])
00d4f518 79efd3a7 00191950 00d4f5b0 00d4f63c mscorwks!invokeCompileMethod+0x31 (FPO: [Non-Fpo])
00d4f570 79ef9c64 00191950 00d4f5b0 00000000 mscorwks!CallCompileMethodWithSEHWrapper+0x84 (FPO: [Non-Fpo])
00d4f928 79ef9a68 006f5718 001d9938 00107210 mscorwks!UnsafeJitFunction+0x230 (FPO: [Non-Fpo])
00d4f9cc 79ef9905 001d9938 00000000 a8e559ac mscorwks!MethodDesc::MakeJitWorker+0x1c1 (FPO: [Non-Fpo])
00d4fa24 79e79091 00000000 a8e559fc 00d4fc78 mscorwks!MethodDesc::DoPrestub+0x486 (FPO: [Non-Fpo])
00d4fa74 003c1efe 00d4faa4 a82bfd52 010646c4 mscorwks!PreStubWorker+0xeb (FPO: [Non-Fpo])
WARNING: Frame IP not in any known module. Following frames may be wrong.
00d4fa8c 793e25cf 00000000 011509f0 01063ff4 0x3c1efe
00d4faac 793e25cf 01150a08 79366b3d 00d4fae0 mscorlib_ni+0x3225cf
00d4fab4 79366b3d 00d4fae0 006f2010 011509f0 mscorlib_ni+0x3225cf
00d4fac8 793e2734 011509f0 00000000 0206101c mscorlib_ni+0x2a6b3d
00d4fae0 793e26ac 00d4fb04 00d4fb20 0019f9e0 mscorlib_ni+0x322734
00d4faf4 79e7c0e3 a8e558a4 7915faa4 00d4fb84 mscorlib_ni+0x3226ac
00000000 00000000 00000000 00000000 00000000 mscorwks!CallDescrWorker+0x33

   4  Id: ebc.b54 Suspend: 1 Teb: 7ffd8000 Unfrozen
ChildEBP RetAddr  Args to Child
00fafe14 7c90daaa 77e765e3 000002bc 00faff74 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
00fafe18 77e765e3 000002bc 00faff74 00000000 ntdll!NtReplyWaitReceivePortEx+0xc (FPO: [5,0,0])
00faff80 77e76caf 00faffa8 77e76ad1 001994d8 rpcrt4!LRPC_ADDRESS::ReceiveLotsaCalls+0x12a (FPO: [Non-Fpo])
00faff88 77e76ad1 001994d8 00000000 00d4ebe8 rpcrt4!RecvLotsaCallsWrapper+0xd (FPO: [Non-Fpo])
00faffa8 77e76c97 0017a9b0 00faffec 7c80b729 rpcrt4!BaseCachedThreadRoutine+0x79 (FPO: [Non-Fpo])
00faffb4 7c80b729 00199218 00000000 00d4ebe8 rpcrt4!ThreadStartRoutine+0x1a (FPO: [Non-Fpo])
00faffec 00000000 77e76c7d 00199218 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   5  Id: ebc.194 Suspend: 1 Teb: 7ffd6000 Unfrozen
ChildEBP RetAddr  Args to Child
0382fce8 7c90df4a 7c929cb6 00000015 0382fd30 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0382fcec 7c929cb6 00000015 0382fd30 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
0382ffb4 7c80b729 00000000 7c80ae40 0000ffff ntdll!RtlpWaitThread+0x13d (FPO: [Non-Fpo])
0382ffec 00000000 7c929b8f 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   6  Id: ebc.e9c Suspend: 1 Teb: 7ffd4000 Unfrozen
ChildEBP RetAddr  Args to Child
03a2fec8 7c90df4a 7c809590 00000003 03a2fef4 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03a2fecc 7c809590 00000003 03a2fef4 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
03a2ff68 7c80a115 00000003 76a61348 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
03a2ff84 769c87bd 00000003 76a61348 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
03a2ffb4 7c80b729 00000000 00000000 00000000 userenv!NotificationThread+0x5f (FPO: [Non-Fpo])
03a2ffec 00000000 769c8761 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   7  Id: ebc.fec Suspend: 1 Teb: 7ff4f000 Unfrozen
ChildEBP RetAddr  Args to Child
03c9ccd8 7c90df5a 7c91b24b 0000060c 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03c9ccdc 7c91b24b 0000060c 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
03c9cd64 7c901046 0023ba38 771c9bb8 7723ba38 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
03c9cd6c 771c9bb8 7723ba38 00000003 038609b0 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
03c9cd8c 7722065c 03869218 00000000 00237788 wininet!CConMgr::CreateUniqueFile+0x21 (FPO: [Non-Fpo])
03c9cdb0 7722127e 03869218 00000000 00237788 wininet!CreateUrlCacheEntryA+0x5d (FPO: [Non-Fpo])
03c9ce04 7a195a5a 03872320 00000000 7a195fe4 wininet!CreateUrlCacheEntryW+0x183 (FPO: [Non-Fpo])
03c9ce64 7a195dcb 03872320 00000000 7a195fe4 mscorwks!CreateUrlCacheEntryW_NoThrow+0x30 (FPO: [Non-Fpo])
03c9d4e0 7a196399 00000001 00000001 80070002 mscorwks!CDebugLog::DumpDebugLog+0x130 (FPO: [Non-Fpo])
03c9d4f4 7a17d78f 03864b60 00000001 00000001 mscorwks!CDebugLog::Flush+0x53 (FPO: [Non-Fpo])
03c9d564 79ef3441 038659f8 79eef384 00000000 mscorwks!CAssemblyName::BindToObject+0x674 (FPO: [Non-Fpo])
03c9d5dc 79f785cb 038654c0 03c9d5b0 038659e8 mscorwks!FusionBind::RemoteLoad+0x14d (FPO: [Non-Fpo])
03c9d664 79ef3078 038654c0 038659b0 03c9da34 mscorwks!FusionBind::LoadAssembly+0x223 (FPO: [Non-Fpo])
03c9d910 79ef0503 03862758 00000001 03c9da34 mscorwks!AssemblySpec::FindAssemblyFile+0xdc (FPO: [Non-Fpo])
03c9da7c 79edf037 03c9db70 00000001 00000000 mscorwks!AppDomain::BindAssemblySpec+0x18d (FPO: [Non-Fpo])
03c9dae4 79f1d707 0000000b 00000000 03c9dc3c mscorwks!AssemblySpec::LoadDomainAssembly+0x114 (FPO: [Non-Fpo])
03c9db08 79f22e94 0000000b 00000000 03c9dc3c mscorwks!AssemblySpec::LoadAssembly+0x1d (FPO: [Non-Fpo])
03c9dc54 79400e07 00000000 00000001 03c9dcdc mscorwks!AssemblyNative::Load+0x240 (FPO: [Non-Fpo])
03c9dca8 7939b788 00000000 03c9dcdc 03c9dcec mscorlib_ni+0x340e07
03c9dcdc 79398fdb 03837a00 00000000 03c9dd2c mscorlib_ni+0x2db788
03c9dcec 79399653 00000000 00000000 00000000 mscorlib_ni+0x2d8fdb
03c9dd2c 79e7c068 03c9e154 00000001 03c9e224 mscorlib_ni+0x2d9653
03c9ddac 79f290ba 03c9e154 00000001 03c9e224 mscorwks!CallDescrWorkerWithHandler+0xa3 (FPO: [Non-Fpo])
03c9ddcc 79f29061 03c9e150 00000001 03c9e224 mscorwks!DispatchCallBody+0x1e (FPO: [Non-Fpo])
03c9de30 79f50be1 03c9e150 00000001 03c9e224 mscorwks!DispatchCallDebuggerWrapper+0x3d (FPO: [Non-Fpo])
03c9ded8 79f558f9 03c9e150 00000001 03c9e224 mscorwks!DispatchCall+0xb3 (FPO: [Non-Fpo])
03c9e094 79f54e3c 03c9e268 03c9e13c 79f54e03 mscorwks!CrossDomainChannel::MarshalAndCall_Wrapper+0x4ad (FPO: [Non-Fpo])
03c9e0a0 79f54e03 03c9e268 03c9e130 79f495f5 mscorwks!MarshalAndCall_Wrapper2+0xf (FPO: [Non-Fpo])
03c9e13c 79f55507 00000002 79fa10af 03c9e268 mscorwks!MakeCallWithAppDomainTransition+0xbc (FPO: [Non-Fpo])
03c9f61c 79f51053 03c9f858 abf855e4 03c9f6f0 mscorwks!CrossDomainChannel::MarshalAndCall+0x7a6 (FPO: [Non-Fpo])
03c9f66c 79f50fd8 03c9f858 abf8553c 03c9f880 mscorwks!CrossDomainChannel::ExecuteCrossDomainCall+0x7d (FPO: [Non-Fpo])
03c9f6b4 79f50ea0 03c9f880 03c9f858 abf85bc8 mscorwks!CrossDomainChannel::CheckCrossDomainCall+0xdd (FPO: [Non-Fpo])
03c9f840 003c253d 03c9f880 03837a00 03c9f858 mscorwks!CTPMethodTable::OnCall+0xa6 (FPO: [Non-Fpo])
WARNING: Frame IP not in any known module. Following frames may be wrong.
03c9f8e4 79e790d2 0115229c 01064430 00000000 0x3c253d
03c9f98c 793e25cf 00000000 01150994 01063ff4 mscorwks!PreStubWorker+0x139 (FPO: [Non-Fpo])
03c9f9ac 793e25cf 011509ac 79366b3d 03c9f9e0 mscorlib_ni+0x3225cf
03c9f9b4 79366b3d 03c9f9e0 006f2010 01150994 mscorlib_ni+0x3225cf
03c9f9c8 793e2734 01150994 00000000 0206101c mscorlib_ni+0x2a6b3d
03c9f9e0 793e26ac 03c9fa04 03c9fa20 03837a00 mscorlib_ni+0x322734
03c9f9f4 79e7c0e3 746e696f 00007265 03c9fa84 mscorlib_ni+0x3226ac
00000000 00000000 00000000 00000000 00000000 mscorwks!CallDescrWorker+0x33

   8  Id: ebc.c84 Suspend: 1 Teb: 7ff4e000 Unfrozen
ChildEBP RetAddr  Args to Child
03d9fe08 7c90d21a 7c8023f1 00000000 03d9fe3c ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03d9fe0c 7c8023f1 00000000 03d9fe3c 00000000 ntdll!NtDelayExecution+0xc (FPO: [2,0,0])
03d9fe64 79f4c26f 000001f4 00000000 abe85d10 kernel32!SleepEx+0x61 (FPO: [Non-Fpo])
03d9fe98 79f270ec 000001f4 00000000 abe85d5c mscorwks!EESleepEx+0xa3 (FPO: [Non-Fpo])
03d9fed4 79f27090 000001f4 00000000 03d9ffb4 mscorwks!__DangerousSwitchToThread+0x75 (FPO: [Non-Fpo])
03d9fee4 79f4c122 000001f4 12b60d16 0000000a mscorwks!__SwitchToThread+0xd (FPO: [Non-Fpo])
03d9ffb4 7c80b729 00000000 7c910222 7c91019b mscorwks!ThreadpoolMgr::GateThreadStart+0xa1 (FPO: [Non-Fpo])
03d9ffec 00000000 79f4c08d 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   9  Id: ebc.e34 Suspend: 1 Teb: 7ff4c000 Unfrozen
ChildEBP RetAddr  Args to Child
0411febc 7c90df4a 7c809590 00000002 0411fee8 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0411fec0 7c809590 00000002 0411fee8 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
0411ff5c 7c80a115 00000002 0411ff9c 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
0411ff78 60f83739 00000002 0411ff9c 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
0411ffac 60f83763 0411ffec 7c80b729 60f8c2b8 mqutil!CCancelRpc::ProcessEvents+0x7b (FPO: [Non-Fpo])
0411ffb4 7c80b729 60f8c2b8 7c912d78 00000000 mqutil!CCancelRpc::CancelThread+0xd (FPO: [Non-Fpo])
0411ffec 00000000 60f83756 60f8c2b8 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

  10  Id: ebc.3d8 Suspend: 1 Teb: 7ffda000 Unfrozen
ChildEBP RetAddr  Args to Child
0426fb38 7c90df5a 7c8025db 000000cc 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0426fb3c 7c8025db 000000cc 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
0426fba0 79e718ff 000000cc ffffffff 00000000 kernel32!WaitForSingleObjectEx+0xa8 (FPO: [Non-Fpo])
0426fbe4 79e718c8 000000cc ffffffff 00000000 mscorwks!PEImage::LoadImage+0x1af (FPO: [Non-Fpo])
0426fc34 79e7187d ffffffff 00000000 00000000 mscorwks!CLREvent::WaitEx+0x117 (FPO: [Non-Fpo])
0426fc48 79f6694c ffffffff 00000000 00000000 mscorwks!CLREvent::Wait+0x17 (FPO: [Non-Fpo])
0426fd14 79ebaf8e 03862390 7c90d06a 7c90e45f mscorwks!AppDomain::ADUnloadThreadStart+0x308 (FPO: [Non-Fpo])
0426ffb4 7c80b729 03848570 00000000 03837a00 mscorwks!Thread::intermediateThreadProc+0x49 (FPO: [Non-Fpo])
0426ffec 00000000 79ebaf48 03848570 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

# 11  Id: ebc.a10 Suspend: 1 Teb: 7ffd7000 Unfrozen
ChildEBP RetAddr  Args to Child
00b9ffc8 7c951e40 00000005 00000004 00000001 ntdll!DbgBreakPoint (FPO: [0,0,0])
00b9fff4 00000000 00000000 00905a4d 00000003 ntdll!DbgUiRemoteBreakin+0x2d (FPO: [Non-Fpo])
</code>```

Sorry for the long paste...

Now, the code has a long list of dependencies, some managed (.net 1.0, 1.1, 2.0) and some unmanaged.
None of the 'syncblk', 'locks' or 'dlk' (from sosex) show anything, but the deadlock is there and it is reported by DebugDiag analyzes on the memory dump (and the service is locked not doing any processing).

Considering my poor knowledge of WinDbg, how can I find out the actual cause of this deadlock? Or make sure I can avoid it?

The issue only seem to appear when .net 4.0 is also installed. I know that the framework is loading the latest version of mscoreei.dll, but this seems to only be a catalyst not the actual cause.
And the issue in all scenarios seem to be due to a deadlock between a dll load and GC (and it might be triggered by the load of another win service).
All managed threads are marked as PreEmptive  GC "Enabled".

The system is WinXP+ SP3 + .net 2.0 + SP1/SP2 and + .net 4.0.

Thanks,
florin

答:
Ended up opening a support ticket to MS.
It was a combination of: 1st time assembly loading (ngen), mixed assemblies, fusion log being enabled.
The workaround was to put merge code from 2 windows services.

Hope in the near future to be able to rewrite some code and get rid of some dependencies (unmanaged c++, .net 1.0 & 1.1)

ContentLicense: CC BY-SA 2.5

Title: .Net app deadlock and GC

Body:
I'm working on a .net system, which under some special conditions (.net 2.20 AND .net 4.0 installed) generates a deadlock in one of (win) services. Using WinDbg i could find out that:

In thread 7:

0:007> !clrstack
OS Thread Id: 0xfec (7)
ESP       EIP
03c9dbd8 7c90e514 [HelperMethodFrame_PROTECTOBJ: 03c9dbd8] System.Reflection.Assembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
03c9dc70 79400e07 System.Reflection.Assembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
03c9dc90 7935c5e0 System.Reflection.Assembly.InternalLoad(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean)
03c9dcb8 7939b788 System.Reflection.Assembly.InternalLoadFrom(System.String, System.Security.Policy.Evidence, Byte[], System.Configuration.Assemblies.AssemblyHashAlgorithm, Boolean, System.Threading.StackCrawlMark ByRef)
03c9dcdc 7939b725 System.Reflection.Assembly.LoadFrom(System.String, System.Security.Policy.Evidence)
03c9dce4 79398fdb System.Activator.CreateInstanceFrom(System.String, System.String, Boolean, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[], System.Security.Policy.Evidence)
03c9dd10 79399653 System.AppDomain.CreateInstanceFrom(System.String, System.String)
03c9dd1c 793b8e39 System.AppDomain.CreateInstanceFromAndUnwrap(System.String, System.String)
03c9df48 79e7c0e3 [GCFrame: 03c9df48]
03c9df64 79e7c0e3 [GCFrame: 03c9df64]
03c9e0d4 79e7c0e3 [ContextTransitionFrame: 03c9e0d4]
03c9e1d8 79e7c0e3 [GCFrame: 03c9e1d8]
03c9e1bc 79e7c0e3 [GCFrame: 03c9e1bc]
03c9f43c 79e7c0e3 [CustomGCFrame: 03c9f43c]
03c9f450 79e7c0e3 [CustomGCFrame: 03c9f450]
03c9f464 79e7c0e3 [CustomGCFrame: 03c9f464]
03c9f478 79e7c0e3 [CustomGCFrame: 03c9f478]
03c9f48c 79e7c0e3 [CustomGCFrame: 03c9f48c]
03c9f4a0 79e7c0e3 [CustomGCFrame: 03c9f4a0]
03c9f4b4 79e7c0e3 [CustomGCFrame: 03c9f4b4]
03c9f880 79e7c0e3 [TPMethodFrame: 03c9f880] System.AppDomain.CreateInstanceFromAndUnwrap(System.String, System.String)
03c9f894 00a64498 Roche.RIG.CLink.DomainObject.Create[[System.__Canon, mscorlib]](System.String, Roche.RIG.CLink.CoreSystem.Interfaces.IBaseCoreSystem, Roche.RIG.CLink.TypeLifeManagementAction)
03c9f8dc 00acf220 Roche.RIG.SmartCom.DomainMgr.Load[[System.__Canon, mscorlib]](System.String)
03c9f92c 00acf075 Roche.RIG.SmartCom.DomainMgr.GetTunnel()
03c9f968 00acef05 Roche.RIG.SmartCom.CoreSystem.StartupTunnel(System.Object)
03c9f9b4 793e25cf System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(System.Object)
03c9f9bc 79366b3d System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
03c9f9d4 793e2734 System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback)
03c9f9e8 793e26ac System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(System.Object)
03c9fb78 79e7c0e3 [GCFrame: 03c9fb78]

and in the other thread (thread 3):

0:003> !clrstack
OS Thread Id: 0xb08 (3)
ESP       EIP
00d4eac4 7c90e514 [GCFrame: 00d4eac4]
00d4faa4 7c90e514 [PrestubMethodFrame: 00d4faa4] Roche.RIG.SmartCom.CoreSystem.StartupTasks(System.Object)
00d4fab4 793e25cf System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(System.Object)
00d4fabc 79366b3d System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
00d4fad4 793e2734 System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback)
00d4fae8 793e26ac System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(System.Object)
00d4fc78 79e7c0e3 [GCFrame: 00d4fc78]

Output of !locks

0:007> !locks

CritSec +157d20 at 00157d20
LockCount          1
RecursionCount     1
OwningThread       fec
EntryCount         1
ContentionCount    1
*** Locked

CritSec wininet!GlobalCacheCritSect+0 at 7723ba38
LockCount          4
RecursionCount     4
OwningThread       b08
EntryCount         1
ContentionCount    1
*** Locked

CritSec +1a1310 at 001a1310
LockCount          0
RecursionCount     1
OwningThread       b08
EntryCount         0
ContentionCount    0
*** Locked

Scanned 1212 critical sections

Output of syncblk

0:003> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner
-----------------------------
Total           370
CCW             1
RCW             319
ComClassFactory 0
Free            0

Output of ~*kv 90

    0:007> ~*kv 90

       0  Id: ebc.edc Suspend: 1 Teb: 7ffdd000 Unfrozen
    ChildEBP RetAddr  Args to Child
    0012f090 7c90d9da 7c801879 000001a4 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    0012f094 7c801879 000001a4 00000000 00000000 ntdll!NtReadFile+0xc (FPO: [9,0,0])
    0012f0fc 77df348b 000001a4 0012f1c8 00000216 kernel32!ReadFile+0x16c (FPO: [Non-Fpo])
    0012f128 77df331f 000001a4 0012f1c8 00000216 advapi32!ScGetPipeInput+0x2a (FPO: [Non-Fpo])
    0012f19c 77df3628 000001a4 0012f1c8 00000216 advapi32!ScDispatcherLoop+0x3f (FPO: [Non-Fpo])
    0012f3fc 006ea31e 0019c3f8 a82bfd52 00000000 advapi32!StartServiceCtrlDispatcherW+0xe3 (FPO: [Non-Fpo])
    *** WARNING: Unable to verify checksum for System.ServiceProcess.ni.dll
    WARNING: Frame IP not in any known module. Following frames may be wrong.
    0012f418 67a241d2 0106174c 01061ab0 0019c400 0x6ea31e
    00000000 00000000 00000000 00000000 00000000 System_ServiceProcess_ni+0x41d2

       1  Id: ebc.d1c Suspend: 1 Teb: 7ffdc000 Unfrozen
    ChildEBP RetAddr  Args to Child
    0082fe38 7c90df4a 7c809590 00000003 0082fe64 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    0082fe3c 7c809590 00000003 0082fe64 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
    0082fed8 7c80a115 00000003 0082ff1c 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
    0082fef4 79ed25eb 00000003 0082ff1c 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
    0082ff54 79ed2548 a8b35c0c 00000000 79ece48c mscorwks!DebuggerRCThread::MainLoop+0xe9 (FPO: [Non-Fpo])
    0082ff84 79ed2477 a8b35c3c 79eb4145 79ece48c mscorwks!DebuggerRCThread::ThreadProc+0xe5 (FPO: [Non-Fpo])
    0082ffb4 7c80b729 00000000 79eb4145 79ece48c mscorwks!DebuggerRCThread::ThreadProcStatic+0x9c (FPO: [Non-Fpo])
    0082ffec 00000000 79ed2431 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

       2  Id: ebc.104 Suspend: 1 Teb: 7ffdb000 Unfrozen
    ChildEBP RetAddr  Args to Child
    009ffcd0 7c90df4a 7c809590 00000002 009ffcfc ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    009ffcd4 7c809590 00000002 009ffcfc 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
    009ffd70 7c80a115 00000002 7a3b9248 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
    009ffd8c 79e719ab 00000002 7a3b9248 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
    009ffdac 79ef8cd9 0016e5d0 009ffeb0 0016edc8 mscorwks!WKS::WaitForFinalizerEvent+0x77 (FPO: [Non-Fpo])
    009ffdc0 79ebab37 009ffeb0 00000000 00000000 mscorwks!WKS::GCHeap::FinalizerThreadWorker+0x79 (FPO: [Non-Fpo])
    009ffdd4 79ebaad3 009ffeb0 009ffe5c 79f495f5 mscorwks!Thread::DoADCallBack+0x32a (FPO: [Non-Fpo])
    009ffe68 79eba9f7 009ffeb0 a8ae5d2c 00000000 mscorwks!Thread::ShouldChangeAbortToUnload+0xe3 (FPO: [Non-Fpo])
    009ffea4 79ebbe48 009ffeb0 00000000 00158500 mscorwks!Thread::ShouldChangeAbortToUnload+0x30a (FPO: [Non-Fpo])
    009ffecc 79ebbe12 79ef8c6c 00000008 009fff14 mscorwks!ManagedThreadBase_NoADTransition+0x32 (FPO: [Non-Fpo])
    009ffedc 79ebb42b 79ef8c6c a8ae5c9c 00000000 mscorwks!ManagedThreadBase::FinalizerBase+0xd (FPO: [Non-Fpo])
    009fff14 79ebaf8e 00000000 8706da80 804fb078 mscorwks!WKS::GCHeap::FinalizerThreadStart+0xbb (FPO: [Non-Fpo])
    009fffb4 7c80b729 0016edc8 00730074 00610020 mscorwks!Thread::intermediateThreadProc+0x49 (FPO: [Non-Fpo])
    009fffec 00000000 79ebaf48 0016edc8 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

       3  Id: ebc.b08 Suspend: 1 Teb: 7ffd9000 Unfrozen
    ChildEBP RetAddr  Args to Child
    00d4d7a0 7c90df5a 7c91b24b 00000610 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
    00d4d7a4 7c91b24b 00000610 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
    00d4d82c 7c901046 00157d20 7a08a990 00157d20 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
    00d4d834 7a08a990 00157d20 79e83b8f 00157d20 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
    00d4d83c 79e83b8f 00157d20 a8e57bf0 001dac60 mscorwks!UnsafeEEEnterCriticalSection+0x18 (FPO: [1,0,0])
    00d4d878 79e75c62 00d4d88c 79e75c56 00157d20 mscorwks!CrstBase::Enter+0x13c (FPO: [Non-Fpo])
    00d4d880 79e75c56 00157d20 00d4d89c 79e75c4a mscorwks!EEEnterCriticalSection+0xb (FPO: [Non-Fpo])
    00d4d88c 79e75c4a 7a3c38b0 00157d20 00d4df10 mscorwks!CExecutionEngine::AcquireLock+0xb (FPO: [Non-Fpo])
    00d4d89c 79eec124 00157d20 8000000a 7a195ccc mscorwks!ClrEnterCriticalSection+0x11 (FPO: [Non-Fpo])
    00d4d8a8 7a195ccc a8e57c98 0385d008 8000000a mscorwks!CCriticalSection::Lock+0x17 (FPO: [0,0,4])
    00d4df10 7a196399 00000001 00000001 80070002 mscorwks!CDebugLog::DumpDebugLog+0x5b (FPO: [Non-Fpo])
    00d4df24 7a17d78f 001dac60 00000001 00000001 mscorwks!CDebugLog::Flush+0x53 (FPO: [Non-Fpo])
    00d4df94 79ef3441 03858a40 79eef384 00000000 mscorwks!CAssemblyName::BindToObject+0x674 (FPO: [Non-Fpo])
    00d4e00c 79ef3261 00173918 00d4dfe0 03858a30 mscorwks!FusionBind::RemoteLoad+0x14d (FPO: [Non-Fpo])
    00d4e094 79ef3078 00173918 00179dd0 00d4e464 mscorwks!FusionBind::LoadAssembly+0x127 (FPO: [Non-Fpo])
    00d4e340 79ef0503 00158500 00000001 00d4e464 mscorwks!AssemblySpec::FindAssemblyFile+0xdc (FPO: [Non-Fpo])
    00d4e4ac 79ee1a9a 00d4e4d4 00000001 00000000 mscorwks!AppDomain::BindAssemblySpec+0x18d (FPO: [Non-Fpo])

00d4e544 79ee1958 23000010 00000000 a8e5466c mscorwks!PEFile::LoadAssembly+0x95 (FPO: [Non-Fpo])
00d4e5e4 79f07846 00158500 23000010 a8e545a8 mscorwks!Module::LoadAssembly+0xee (FPO: [Non-Fpo])
00d4e620 79ef70d9 006f4c1c 010000a3 00000000 mscorwks!Assembly::FindModuleByTypeRef+0x113 (FPO: [Non-Fpo])
00d4e670 79e82979 00d4e704 00000000 00000000 mscorwks!ClassLoader::LoadTypeDefOrRefThrowing+0xfc (FPO: [Non-Fpo])
00d4e6a0 79e9ecb3 00d4e704 006f4c1c 010000a3 mscorwks!ClassLoader::LoadTypeDefOrRefOrSpecThrowing+0xa0 (FPO: [Non-Fpo])
00d4e734 79e9bab0 006f4c1c 0a000148 00d4e9c4 mscorwks!MemberLoader::GetDescFromMemberDefOrRefThrowing+0x210 (FPO: [Non-Fpo])
00d4e9bc 79efa4a9 00000001 0a000148 00d4eb08 mscorwks!MemberLoader::GetMethodDescFromMemberDefOrRefOrSpecThrowing+0x219 (FPO: [Non-Fpo])
00d4ea48 79efaf4b 006f4c1c 0a000148 00d4eb40 mscorwks!MemberLoader::GetMethodDescFromMemberDefOrRefOrSpecNT+0x76 (FPO: [Non-Fpo])
00d4eb50 79efae1f 006f4c1c 0a000148 006f5718 mscorwks!CEEInfo::findMethodInternal+0x154 (FPO: [Non-Fpo])
00d4ebd0 79061fd6 00d4f5bc 006f4c1c 8a000101 mscorwks!CEEInfo::findMethod+0x107 (FPO: [Non-Fpo])
00d4ebe8 7906535a 8a000148 006f4c1c 006f5718 mscorjit!Compiler::eeFindMethod+0x22 (FPO: [Non-Fpo])
00d4ecb8 79063324 00000028 0a000148 baadbeef mscorjit!Compiler::impImportCall+0xa7 (FPO: [Non-Fpo])
00d4f290 790635c3 00b52c70 807e6cc2 00b53250 mscorjit!Compiler::impImportBlockCode+0x29ae (FPO: [Non-Fpo])
00d4f314 7906355b 00b52c70 00000000 00b50010 mscorjit!Compiler::impImportBlock+0x20c (FPO: [Non-Fpo])
00d4f32c 79063494 00b52bb8 00b50010 79064e1c mscorjit!Compiler::impImport+0xe5 (FPO: [Non-Fpo])
00d4f338 79064e1c 00b50010 00d4f39c 790614e6 mscorjit!Compiler::fgImport+0x20 (FPO: [0,0,4])
00d4f344 790614e6 00d4f464 00d4f6c8 00d4f458 mscorjit!Compiler::compCompile+0xb (FPO: [Non-Fpo])
00d4f39c 79061236 006f4c1c 00d4f5b0 00d4f63c mscorjit!Compiler::compCompile+0x2df (FPO: [Non-Fpo])
00d4f430 7906118c 00d4f5b0 00d4f63c 00d4f464 mscorjit!jitNativeCode+0xb8 (FPO: [Non-Fpo])
00d4f468 79efd49f 790b22a0 00d4f5b0 00d4f63c mscorjit!CILJit::compileMethod+0x3d (FPO: [Non-Fpo])
00d4f4d4 79efd415 00191950 00d4f5b0 00d4f63c mscorwks!invokeCompileMethodHelper+0x72 (FPO: [Non-Fpo])
00d4f518 79efd3a7 00191950 00d4f5b0 00d4f63c mscorwks!invokeCompileMethod+0x31 (FPO: [Non-Fpo])
00d4f570 79ef9c64 00191950 00d4f5b0 00000000 mscorwks!CallCompileMethodWithSEHWrapper+0x84 (FPO: [Non-Fpo])
00d4f928 79ef9a68 006f5718 001d9938 00107210 mscorwks!UnsafeJitFunction+0x230 (FPO: [Non-Fpo])
00d4f9cc 79ef9905 001d9938 00000000 a8e559ac mscorwks!MethodDesc::MakeJitWorker+0x1c1 (FPO: [Non-Fpo])
00d4fa24 79e79091 00000000 a8e559fc 00d4fc78 mscorwks!MethodDesc::DoPrestub+0x486 (FPO: [Non-Fpo])
00d4fa74 003c1efe 00d4faa4 a82bfd52 010646c4 mscorwks!PreStubWorker+0xeb (FPO: [Non-Fpo])
WARNING: Frame IP not in any known module. Following frames may be wrong.
00d4fa8c 793e25cf 00000000 011509f0 01063ff4 0x3c1efe
00d4faac 793e25cf 01150a08 79366b3d 00d4fae0 mscorlib_ni+0x3225cf
00d4fab4 79366b3d 00d4fae0 006f2010 011509f0 mscorlib_ni+0x3225cf
00d4fac8 793e2734 011509f0 00000000 0206101c mscorlib_ni+0x2a6b3d
00d4fae0 793e26ac 00d4fb04 00d4fb20 0019f9e0 mscorlib_ni+0x322734
00d4faf4 79e7c0e3 a8e558a4 7915faa4 00d4fb84 mscorlib_ni+0x3226ac
00000000 00000000 00000000 00000000 00000000 mscorwks!CallDescrWorker+0x33

   4  Id: ebc.b54 Suspend: 1 Teb: 7ffd8000 Unfrozen
ChildEBP RetAddr  Args to Child
00fafe14 7c90daaa 77e765e3 000002bc 00faff74 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
00fafe18 77e765e3 000002bc 00faff74 00000000 ntdll!NtReplyWaitReceivePortEx+0xc (FPO: [5,0,0])
00faff80 77e76caf 00faffa8 77e76ad1 001994d8 rpcrt4!LRPC_ADDRESS::ReceiveLotsaCalls+0x12a (FPO: [Non-Fpo])
00faff88 77e76ad1 001994d8 00000000 00d4ebe8 rpcrt4!RecvLotsaCallsWrapper+0xd (FPO: [Non-Fpo])
00faffa8 77e76c97 0017a9b0 00faffec 7c80b729 rpcrt4!BaseCachedThreadRoutine+0x79 (FPO: [Non-Fpo])
00faffb4 7c80b729 00199218 00000000 00d4ebe8 rpcrt4!ThreadStartRoutine+0x1a (FPO: [Non-Fpo])
00faffec 00000000 77e76c7d 00199218 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   5  Id: ebc.194 Suspend: 1 Teb: 7ffd6000 Unfrozen
ChildEBP RetAddr  Args to Child
0382fce8 7c90df4a 7c929cb6 00000015 0382fd30 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0382fcec 7c929cb6 00000015 0382fd30 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
0382ffb4 7c80b729 00000000 7c80ae40 0000ffff ntdll!RtlpWaitThread+0x13d (FPO: [Non-Fpo])
0382ffec 00000000 7c929b8f 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   6  Id: ebc.e9c Suspend: 1 Teb: 7ffd4000 Unfrozen
ChildEBP RetAddr  Args to Child
03a2fec8 7c90df4a 7c809590 00000003 03a2fef4 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03a2fecc 7c809590 00000003 03a2fef4 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
03a2ff68 7c80a115 00000003 76a61348 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
03a2ff84 769c87bd 00000003 76a61348 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
03a2ffb4 7c80b729 00000000 00000000 00000000 userenv!NotificationThread+0x5f (FPO: [Non-Fpo])
03a2ffec 00000000 769c8761 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   7  Id: ebc.fec Suspend: 1 Teb: 7ff4f000 Unfrozen
ChildEBP RetAddr  Args to Child
03c9ccd8 7c90df5a 7c91b24b 0000060c 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03c9ccdc 7c91b24b 0000060c 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
03c9cd64 7c901046 0023ba38 771c9bb8 7723ba38 ntdll!RtlpWaitForCriticalSection+0x132 (FPO: [Non-Fpo])
03c9cd6c 771c9bb8 7723ba38 00000003 038609b0 ntdll!RtlEnterCriticalSection+0x46 (FPO: [1,0,0])
03c9cd8c 7722065c 03869218 00000000 00237788 wininet!CConMgr::CreateUniqueFile+0x21 (FPO: [Non-Fpo])
03c9cdb0 7722127e 03869218 00000000 00237788 wininet!CreateUrlCacheEntryA+0x5d (FPO: [Non-Fpo])
03c9ce04 7a195a5a 03872320 00000000 7a195fe4 wininet!CreateUrlCacheEntryW+0x183 (FPO: [Non-Fpo])
03c9ce64 7a195dcb 03872320 00000000 7a195fe4 mscorwks!CreateUrlCacheEntryW_NoThrow+0x30 (FPO: [Non-Fpo])
03c9d4e0 7a196399 00000001 00000001 80070002 mscorwks!CDebugLog::DumpDebugLog+0x130 (FPO: [Non-Fpo])
03c9d4f4 7a17d78f 03864b60 00000001 00000001 mscorwks!CDebugLog::Flush+0x53 (FPO: [Non-Fpo])
03c9d564 79ef3441 038659f8 79eef384 00000000 mscorwks!CAssemblyName::BindToObject+0x674 (FPO: [Non-Fpo])
03c9d5dc 79f785cb 038654c0 03c9d5b0 038659e8 mscorwks!FusionBind::RemoteLoad+0x14d (FPO: [Non-Fpo])
03c9d664 79ef3078 038654c0 038659b0 03c9da34 mscorwks!FusionBind::LoadAssembly+0x223 (FPO: [Non-Fpo])
03c9d910 79ef0503 03862758 00000001 03c9da34 mscorwks!AssemblySpec::FindAssemblyFile+0xdc (FPO: [Non-Fpo])
03c9da7c 79edf037 03c9db70 00000001 00000000 mscorwks!AppDomain::BindAssemblySpec+0x18d (FPO: [Non-Fpo])
03c9dae4 79f1d707 0000000b 00000000 03c9dc3c mscorwks!AssemblySpec::LoadDomainAssembly+0x114 (FPO: [Non-Fpo])
03c9db08 79f22e94 0000000b 00000000 03c9dc3c mscorwks!AssemblySpec::LoadAssembly+0x1d (FPO: [Non-Fpo])
03c9dc54 79400e07 00000000 00000001 03c9dcdc mscorwks!AssemblyNative::Load+0x240 (FPO: [Non-Fpo])
03c9dca8 7939b788 00000000 03c9dcdc 03c9dcec mscorlib_ni+0x340e07
03c9dcdc 79398fdb 03837a00 00000000 03c9dd2c mscorlib_ni+0x2db788
03c9dcec 79399653 00000000 00000000 00000000 mscorlib_ni+0x2d8fdb
03c9dd2c 79e7c068 03c9e154 00000001 03c9e224 mscorlib_ni+0x2d9653
03c9ddac 79f290ba 03c9e154 00000001 03c9e224 mscorwks!CallDescrWorkerWithHandler+0xa3 (FPO: [Non-Fpo])
03c9ddcc 79f29061 03c9e150 00000001 03c9e224 mscorwks!DispatchCallBody+0x1e (FPO: [Non-Fpo])
03c9de30 79f50be1 03c9e150 00000001 03c9e224 mscorwks!DispatchCallDebuggerWrapper+0x3d (FPO: [Non-Fpo])
03c9ded8 79f558f9 03c9e150 00000001 03c9e224 mscorwks!DispatchCall+0xb3 (FPO: [Non-Fpo])
03c9e094 79f54e3c 03c9e268 03c9e13c 79f54e03 mscorwks!CrossDomainChannel::MarshalAndCall_Wrapper+0x4ad (FPO: [Non-Fpo])
03c9e0a0 79f54e03 03c9e268 03c9e130 79f495f5 mscorwks!MarshalAndCall_Wrapper2+0xf (FPO: [Non-Fpo])
03c9e13c 79f55507 00000002 79fa10af 03c9e268 mscorwks!MakeCallWithAppDomainTransition+0xbc (FPO: [Non-Fpo])
03c9f61c 79f51053 03c9f858 abf855e4 03c9f6f0 mscorwks!CrossDomainChannel::MarshalAndCall+0x7a6 (FPO: [Non-Fpo])
03c9f66c 79f50fd8 03c9f858 abf8553c 03c9f880 mscorwks!CrossDomainChannel::ExecuteCrossDomainCall+0x7d (FPO: [Non-Fpo])
03c9f6b4 79f50ea0 03c9f880 03c9f858 abf85bc8 mscorwks!CrossDomainChannel::CheckCrossDomainCall+0xdd (FPO: [Non-Fpo])
03c9f840 003c253d 03c9f880 03837a00 03c9f858 mscorwks!CTPMethodTable::OnCall+0xa6 (FPO: [Non-Fpo])
WARNING: Frame IP not in any known module. Following frames may be wrong.
03c9f8e4 79e790d2 0115229c 01064430 00000000 0x3c253d
03c9f98c 793e25cf 00000000 01150994 01063ff4 mscorwks!PreStubWorker+0x139 (FPO: [Non-Fpo])
03c9f9ac 793e25cf 011509ac 79366b3d 03c9f9e0 mscorlib_ni+0x3225cf
03c9f9b4 79366b3d 03c9f9e0 006f2010 01150994 mscorlib_ni+0x3225cf
03c9f9c8 793e2734 01150994 00000000 0206101c mscorlib_ni+0x2a6b3d
03c9f9e0 793e26ac 03c9fa04 03c9fa20 03837a00 mscorlib_ni+0x322734
03c9f9f4 79e7c0e3 746e696f 00007265 03c9fa84 mscorlib_ni+0x3226ac
00000000 00000000 00000000 00000000 00000000 mscorwks!CallDescrWorker+0x33

   8  Id: ebc.c84 Suspend: 1 Teb: 7ff4e000 Unfrozen
ChildEBP RetAddr  Args to Child
03d9fe08 7c90d21a 7c8023f1 00000000 03d9fe3c ntdll!KiFastSystemCallRet (FPO: [0,0,0])
03d9fe0c 7c8023f1 00000000 03d9fe3c 00000000 ntdll!NtDelayExecution+0xc (FPO: [2,0,0])
03d9fe64 79f4c26f 000001f4 00000000 abe85d10 kernel32!SleepEx+0x61 (FPO: [Non-Fpo])
03d9fe98 79f270ec 000001f4 00000000 abe85d5c mscorwks!EESleepEx+0xa3 (FPO: [Non-Fpo])
03d9fed4 79f27090 000001f4 00000000 03d9ffb4 mscorwks!__DangerousSwitchToThread+0x75 (FPO: [Non-Fpo])
03d9fee4 79f4c122 000001f4 12b60d16 0000000a mscorwks!__SwitchToThread+0xd (FPO: [Non-Fpo])
03d9ffb4 7c80b729 00000000 7c910222 7c91019b mscorwks!ThreadpoolMgr::GateThreadStart+0xa1 (FPO: [Non-Fpo])
03d9ffec 00000000 79f4c08d 00000000 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

   9  Id: ebc.e34 Suspend: 1 Teb: 7ff4c000 Unfrozen
ChildEBP RetAddr  Args to Child
0411febc 7c90df4a 7c809590 00000002 0411fee8 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0411fec0 7c809590 00000002 0411fee8 00000001 ntdll!ZwWaitForMultipleObjects+0xc (FPO: [5,0,0])
0411ff5c 7c80a115 00000002 0411ff9c 00000000 kernel32!WaitForMultipleObjectsEx+0x12c (FPO: [Non-Fpo])
0411ff78 60f83739 00000002 0411ff9c 00000000 kernel32!WaitForMultipleObjects+0x18 (FPO: [Non-Fpo])
0411ffac 60f83763 0411ffec 7c80b729 60f8c2b8 mqutil!CCancelRpc::ProcessEvents+0x7b (FPO: [Non-Fpo])
0411ffb4 7c80b729 60f8c2b8 7c912d78 00000000 mqutil!CCancelRpc::CancelThread+0xd (FPO: [Non-Fpo])
0411ffec 00000000 60f83756 60f8c2b8 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

  10  Id: ebc.3d8 Suspend: 1 Teb: 7ffda000 Unfrozen
ChildEBP RetAddr  Args to Child
0426fb38 7c90df5a 7c8025db 000000cc 00000000 ntdll!KiFastSystemCallRet (FPO: [0,0,0])
0426fb3c 7c8025db 000000cc 00000000 00000000 ntdll!ZwWaitForSingleObject+0xc (FPO: [3,0,0])
0426fba0 79e718ff 000000cc ffffffff 00000000 kernel32!WaitForSingleObjectEx+0xa8 (FPO: [Non-Fpo])
0426fbe4 79e718c8 000000cc ffffffff 00000000 mscorwks!PEImage::LoadImage+0x1af (FPO: [Non-Fpo])
0426fc34 79e7187d ffffffff 00000000 00000000 mscorwks!CLREvent::WaitEx+0x117 (FPO: [Non-Fpo])
0426fc48 79f6694c ffffffff 00000000 00000000 mscorwks!CLREvent::Wait+0x17 (FPO: [Non-Fpo])
0426fd14 79ebaf8e 03862390 7c90d06a 7c90e45f mscorwks!AppDomain::ADUnloadThreadStart+0x308 (FPO: [Non-Fpo])
0426ffb4 7c80b729 03848570 00000000 03837a00 mscorwks!Thread::intermediateThreadProc+0x49 (FPO: [Non-Fpo])
0426ffec 00000000 79ebaf48 03848570 00000000 kernel32!BaseThreadStart+0x37 (FPO: [Non-Fpo])

# 11  Id: ebc.a10 Suspend: 1 Teb: 7ffd7000 Unfrozen
ChildEBP RetAddr  Args to Child
00b9ffc8 7c951e40 00000005 00000004 00000001 ntdll!DbgBreakPoint (FPO: [0,0,0])
00b9fff4 00000000 00000000 00905a4d 00000003 ntdll!DbgUiRemoteBreakin+0x2d (FPO: [Non-Fpo])

Sorry for the long paste...

Now, the code has a long list of dependencies, some managed (.net 1.0, 1.1, 2.0) and some unmanaged.
None of the 'syncblk', 'locks' or 'dlk' (from sosex) show anything, but the deadlock is there and it is reported by DebugDiag analyzes on the memory dump (and the service is locked not doing any processing).

Considering my poor knowledge of WinDbg, how can I find out the actual cause of this deadlock? Or make sure I can avoid it?

The issue only seem to appear when .net 4.0 is also installed. I know that the framework is loading the latest version of mscoreei.dll, but this seems to only be a catalyst not the actual cause.
And the issue in all scenarios seem to be due to a deadlock between a dll load and GC (and it might be triggered by the load of another win service).
All managed threads are marked as PreEmptive  GC "Enabled".

The system is WinXP+ SP3 + .net 2.0 + SP1/SP2 and + .net 4.0.

Thanks,
florin


来源: stackexchange

问:
Replicate STUFF in Snowflake SQL
Hello Snowflake Community,

I am attempting to replicate the STUFF function in Snowflake. I didn't find a like-named function on the reference list and so was hoping someone could point me in the right direction?

Googled example

Thank you good folks

DU

答:
Look at ARRAY_AGG. This will get you all the grouped records for a field restructured as an array. For your example in your image:

```<code>SELECT SEC_NAME,ARRAY_AGG(USR_NAME) AS USR_NAME
FROM TABLE_NAME
GROUP BY SEC_NAME
</code>```

If that's not enough, use ARRAY_TO_STRING on top of it.

Reference: https://docs.snowflake.com/en/sql-reference/functions/array_to_string.html

ContentLicense: CC BY-SA 4.0

Title: Replicate STUFF in Snowflake SQL

Body:
Look at ARRAY_AGG. This will get you all the grouped records for a field restructured as an array. For your example in your image:

SELECT SEC_NAME,ARRAY_AGG(USR_NAME) AS USR_NAME
FROM TABLE_NAME
GROUP BY SEC_NAME

If that's not enough, use ARRAY_TO_STRING on top of it.

Reference: https://docs.snowflake.com/en/sql-reference/functions/array_to_string.html


问:
how to search amadeus api one way flight. any idea about that
Help me in the Amadeus API issue flight search section.
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search/api-reference</p>

答:
if you are using GET : simply leave out the returnDate and only use departureDate.

If you are using POST: shouldn't be too much of an issue, since you specify every single leg of the journey on its own in originDestinations . So just enter your desired route there.


问:
How to get CatBoost model's coefficients?
I need to get the parameters to use the model in another program.

I tried  cat_model.coef_, cat_model.intercept_ or what I think. is that possible to catch the params ?

I totally solved this problem, what i was tryna do is named 'saving model'.

```<code> cat_model.save_model('cat_model.cbm')
</code>```

答: Attributes .coef_ and .intercept_ only exist in sklearn applications of linear regression and logistic regression and will give you the slopes and the intercept (if fitted). You can use .feature_importances_  instead.</p>

Body:
I need to get the parameters to use the model in another program.

I tried  cat_model.coef_, cat_model.intercept_ or what I think. is that possible to catch the params ?

I totally solved this problem, what i was tryna do is named 'saving model'.

 cat_model.save_model('cat_model.cbm')


问:
Font Awesome accessibility issue. Use  tags instead of
I am testing my HTML code markup compliance with accessibility standards: http://achecker.ca/checker/index.php. The following is an error I get:

Repair: Replace your i elements with em or strong.

```<code><i class="fa fa-search" title="Search"></i> <span class="sr-only">Search</span>
</code>```

I went through the official Font Awesome docs on the accessibility (https://cdn.fontawesome.com/help#qa-autoa11y), and didn't find any mention of that I need to use different tags for icons. Any ideas on this?

答:
I know it's a 2016 answer... you may use aria-hidden="true" on your tag, like this: , tho.

That's explained on:
https://rules.sonarsource.com/html/RSPEC-1100 and https://www.w3.org/WAI/GL/wiki/Using_aria-hidden%3Dtrue_on_an_icon_font_that_AT_should_ignore

ContentLicense: CC BY-SA 3.0

Title: Font Awesome accessibility issue. Use <em> tags instead of <i>

Body:
I am testing my HTML code markup compliance with accessibility standards: http://achecker.ca/checker/index.php. The following is an error I get:

Repair: Replace your i elements with em or strong.

 Search

I went through the official Font Awesome docs on the accessibility (https://cdn.fontawesome.com/help#qa-autoa11y), and didn't find any mention of that I need to use different tags for icons. Any ideas on this?

Body:
I know it's a 2016 answer... you may use aria-hidden="true" on your tag, like this: <i class="fa fa-search" aria-hidden="true"></i>, tho.

That's explained on:
https://rules.sonarsource.com/html/RSPEC-1100 and https://www.w3.org/WAI/GL/wiki/Using_aria-hidden%3Dtrue_on_an_icon_font_that_AT_should_ignore


问:
Most efficient way to create InputStream from OutputStream
This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream
describes how to create an InputStream from OutputStream:

```<code>new ByteArrayInputStream(out.toByteArray())
</code>```

Other alternatives are to use PipedStreams and new threads which is cumbersome.

I do not like the idea of copying many megabytes to new in memory byte array.
Is there a library that does this more efficiently?

EDIT:

By advice from Laurence Gonsalves, i tried PipedStreams and it turned out they are not that hard to deal with.
Here's the sample code in clojure:

```<code>(defn #^PipedInputStream create-pdf-stream [pdf-info]
  (let [in-stream (new PipedInputStream)
        out-stream (PipedOutputStream. in-stream)]
    (.start (Thread. #(;Here you write into out-stream)))
    in-stream))
</code>```

答:
There is another Open Source library called EasyStream that deals with pipes and thread in a transparent way.
That isn't really complicated if everything goes well. Problems arise when (looking at Laurence Gonsalves example)

class1.putDataOnOutputStream(out);

Throws an exception.
In that example the thread simply completes and the exception is lost, while the outer InputStream might be truncated.

Easystream deals with exception propagation and other nasty problems I've been debugging for about one year. (I'm the mantainer of the library: obviously my solution is the best one ;) )
Here is an example on how to use it:

```<code>final InputStreamFromOutputStream<String> isos = new InputStreamFromOutputStream<String>(){
 @Override
 public String produce(final OutputStream dataSink) throws Exception {
   /*
    * call your application function who produces the data here
    * WARNING: we're in another thread here, so this method shouldn't
    * write any class field or make assumptions on the state of the outer class.
    */
   return produceMydata(dataSink)
 }
};
</code>```

There is also a nice introduction where all other ways to convert an OutputStream into an InputStream are explained. Worth to have a look.

Body:
This page: http://blog.ostermiller.org/convert-java-outputstream-inputstream
describes how to create an InputStream from OutputStream:

new ByteArrayInputStream(out.toByteArray())

Other alternatives are to use PipedStreams and new threads which is cumbersome.

I do not like the idea of copying many megabytes to new in memory byte array.
Is there a library that does this more efficiently?

EDIT:

By advice from Laurence Gonsalves, i tried PipedStreams and it turned out they are not that hard to deal with.
Here's the sample code in clojure:

(defn #^PipedInputStream create-pdf-stream [pdf-info]
  (let [in-stream (new PipedInputStream)
        out-stream (PipedOutputStream. in-stream)]
    (.start (Thread. #(;Here you write into out-stream)))
    in-stream))

Body:
There is another Open Source library called EasyStream that deals with pipes and thread in a transparent way.
That isn't really complicated if everything goes well. Problems arise when (looking at Laurence Gonsalves example)

class1.putDataOnOutputStream(out);

Throws an exception.
In that example the thread simply completes and the exception is lost, while the outer InputStream might be truncated.

Easystream deals with exception propagation and other nasty problems I've been debugging for about one year. (I'm the mantainer of the library: obviously my solution is the best one ;) )
Here is an example on how to use it:

final InputStreamFromOutputStream<String> isos = new InputStreamFromOutputStream<String>(){
 @Override
 public String produce(final OutputStream dataSink) throws Exception {
   /*
    * call your application function who produces the data here
    * WARNING: we're in another thread here, so this method shouldn't
    * write any class field or make assumptions on the state of the outer class.
    */
   return produceMydata(dataSink)
 }
};

There is also a nice introduction where all other ways to convert an OutputStream into an InputStream are explained. Worth to have a look.


问:
Checking params in url with Javascript to change button color
In my rails 6 app, i want to check the id of the params in the Url and change the button with the same id. E.G: http://localhost:3000/en/search?category=9, should change button with id="9"

My Buttons are like so:

```<code> <div class="tooltip-wrap">
  <%= link_to request.params.merge(category: "9"), class: "button is-rounded", id: "9" do %>
  <i class="fas fa-thermometer-full"></i><%= (t "service.title").truncate(17) %>
  <% end %>
  </div>
</code>```

Javascript function

```<code><script>
if (window.location.search.indexOf('category=' + "{n}") > -1){
$('#{n}').addClass('has-background-primary');
};
</script>
</code>```

Url like:

```<code>http://localhost:3000/en/search?category=9
</code>```

答:
Try to do it like this

  <%= link_to request.params.merge(category: "9"), class: "button is-rounded #{'color-class' if params[:category] == '9'}", id: "9" do %>
    <%= (t "service.title").truncate(17) %>
  <% end %>

```

<p>Much cleaner without relying on javascript to properly parse the url and find the parameter.</p>

<p>Seems like this is the best solution until they add the <code>class_names</code> helper in rails 6.1. See here: https://blog.bigbinary.com/2020/02/04/rails-6-1-introduces-class_names-helper.html</p>

<hr>

<p>If you're manually writing out the code for each button like above, you could simplify this a lot by generating it dynamically from a hash in the controller. It has the benefit of being much easier to add/remove categories.</p>

<p>Controller:</p>

<pre class="lang-rb prettyprint-override"><code>@categories = [
               { id: '1', name: 'Category Name', icon: 'fas fa-thermometer-full' },
               { id: '2', name: 'Another Category', icon: 'fas fa-book' }
              ]
</code>```

You could even declare that as a constant in an initializer to use across your entire application.

.html.erb

```<code><% @categories.each do |category| %>
  <div class="tooltip-wrap">
    <%= link_to request.params.merge(category: category[:id]), class: "button is-rounded #{'color-class' if params[:category] == category[:id]}", id: category[:id] do %>
      <i class="<%= category[:icon] %>"></i><%= ("#{category[:name]}").truncate(17) %>
    <% end %>
  </div>
<% end %>
</code>```

You're using a server-side language. Let it do some of the work for you.

Body:
In my rails 6 app, i want to check the id of the params in the Url and change the button with the same id. E.G: http://localhost:3000/en/search?category=9, should change button with id="9"

My Buttons are like so:

  <%= link_to request.params.merge(category: "9"), class: "button is-rounded", id: "9" do %>
  <%= (t "service.title").truncate(17) %>
  <% end %>

Javascript function

Url like:

http://localhost:3000/en/search?category=9

Body:
Try to do it like this

<div class="tooltip-wrap">
  <%= link_to request.params.merge(category: "9"), class: "button is-rounded #{'color-class' if params[:category] == '9'}", id: "9" do %>
    <i class="fas fa-thermometer-full"></i><%= (t "service.title").truncate(17) %>
  <% end %>
</div>

Much cleaner without relying on javascript to properly parse the url and find the parameter.

Seems like this is the best solution until they add the class_names helper in rails 6.1. See here: https://blog.bigbinary.com/2020/02/04/rails-6-1-introduces-class_names-helper.html

If you're manually writing out the code for each button like above, you could simplify this a lot by generating it dynamically from a hash in the controller. It has the benefit of being much easier to add/remove categories.

Controller:

@categories = [
               { id: '1', name: 'Category Name', icon: 'fas fa-thermometer-full' },
               { id: '2', name: 'Another Category', icon: 'fas fa-book' }
              ]

You could even declare that as a constant in an initializer to use across your entire application.

.html.erb

<% @categories.each do |category| %>
  <div class="tooltip-wrap">
    <%= link_to request.params.merge(category: category[:id]), class: "button is-rounded #{'color-class' if params[:category] == category[:id]}", id: category[:id] do %>
      <i class="<%= category[:icon] %>"></i><%= ("#{category[:name]}").truncate(17) %>
    <% end %>
  </div>
<% end %>

You're using a server-side language. Let it do some of the work for you.


问:
Generating a random integer excluding certain values
I have made simple code to generate a random 7 digit number between  1111111 and 9999997

```<code>import random

key = random.randint(1111111, 9999997)

print(key)
</code>```

I need this number to not contain 0, 8 or 9 as the last digit. It also needs to be divisible by 21. How can I do this?

答:
You loop until your number fits your conditions, then break:</p>

```<code>import random

while True:
    key = random.randint(1111111, 9999997)
    if key % 21 == 0 and str(key)[-1] not in "089":
        break

print(key)
</code>```

Body:
I have made simple code to generate a random 7 digit number between  1111111 and 9999997

import random

key = random.randint(1111111, 9999997)

print(key)

I need this number to not contain 0, 8 or 9 as the last digit. It also needs to be divisible by 21. How can I do this?

Body:
You loop until your number fits your conditions, then break:

import random

while True:
    key = random.randint(1111111, 9999997)
    if key % 21 == 0 and str(key)[-1] not in "089":
        break

print(key)


问:
In App Purchase
I am new in iPhone development.

if i want to buy only an image within the application through Apple - In App purchase Payment mode. So what would be the method for this?

NOTE: Dont Want to buy the whole Application.

Thanks in advance.

答:
Refer this blog of In App Purchase

Also refer the apple documentation

You keep the image locked and ask the user to make an in app purchase for it to unlock.

Title: In App Purchase


问:
Google VM RAM for Minecraft Server
I've been tasking with creating a Minecraft server for about 500 players. I've never create a Minecraft server this large before and I think the best way to go about it is (how I've done all my other servers) with Google Cloud. Google Cloud has the following VM options:

I'm thinking about ~100MB per player to be on the safe side, so that's about 50 GB, so I'd say the n2-highmem-8 is probably a good VM to use. Is this overkill? Underkill?

Also, I know that a MC server can't use Multiple CPUs at the same time, so is it a waste paying for 8 Virtual CPUs?

Thanks!

答:
For 500 players, I would recommend a minimum of 6 vCore and 32 GB or more.

You're right with Minecraft mainly using only one thread, so a high CPU Clock speed is most valuable. Also, I would recommend using PaperMC, it's a custom-made better performing Minecraft Server software. Here could you get different server versions if you do not want to use 1.15.2 Minecraft.

Maybe you should look around for different Servers, near your location. I bet you can find something less expensive and with higher Core clocks.

Title: Google VM RAM for Minecraft Server


问:
Create a random binary variable for a subset of observations assigning 1 to a specific proportion of rows
I have a dataframe...

```<code>df <- tibble(
  id = 1:10,
  family = c("a","a","b","b","c", "d", "e", "f", "g", "h")
  )
</code>```

Families will only contain 2 members at most (so they're either individuals or pairs).

For individuals (families with only one row, i.e. id = 5:10), I want to create a column called 'random' that randomly assigns 50% of the entries as 1 and the rest as 0. All other rows (those belonging to families with 2 members) should also equal 0.

By the end, the data should look like the following (depending on which 50% of rows are assigned 1)...

```<code>df <- tibble(
  id = 1:10,
  family = c("a","a","b","b","c", "d", "e", "f", "g", "h"),
  random = c(0, 0, 0, 0, 1, 0, 1, 1, 0, 0)
  )
</code>```

I am mostly using Tidyverse and would like to include it within a pipe.

I am currently trying something along the lines of...

```<code>df %>%
   group_by(family) %>%
   mutate(random = if(n() == 1) *not sure what goes here* else 0)
</code>```

答:
Using data.table

```<code>library(data.table)
setDT(df)[, if(.N > 1) 0 else sample(0:1, 1), family]
</code>```

Body:
I have a dataframe...

df <- tibble(
  id = 1:10,
  family = c("a","a","b","b","c", "d", "e", "f", "g", "h")
  )

Families will only contain 2 members at most (so they're either individuals or pairs).

For individuals (families with only one row, i.e. id = 5:10), I want to create a column called 'random' that randomly assigns 50% of the entries as 1 and the rest as 0. All other rows (those belonging to families with 2 members) should also equal 0.

By the end, the data should look like the following (depending on which 50% of rows are assigned 1)...

df <- tibble(
  id = 1:10,
  family = c("a","a","b","b","c", "d", "e", "f", "g", "h"),
  random = c(0, 0, 0, 0, 1, 0, 1, 1, 0, 0)
  )

I am mostly using Tidyverse and would like to include it within a pipe.

I am currently trying something along the lines of...

df %>%
   group_by(family) %>%
   mutate(random = if(n() == 1) *not sure what goes here* else 0)

Body:
Using data.table

library(data.table)
setDT(df)[, if(.N > 1) 0 else sample(0:1, 1), family]


答:
```<code>valid_numbers = [i for i in range(1111111, 9999997+1) if (i % 10 != 0) and (i % 10 != 8) and (i % 10 != 9) and (i % 21 == 0)]
key = random.choice(valid_numbers)
</code>```

The first line uses a list comprehension with a conditional if to generate a list of all the numbers that fit your criteria.  Note that the second parameter to range needs to be one greater than the last number you need.  To get the last digit of a number you can use the modulo operator % with 10: i % 10 gives the last decimal digit of i.  Likewise i % 21 == 0 tells you if the number divides evenly by 21.

Once you have that list, it's just a matter of picking a number from the list with random.choice.

Title: Generating a random integer excluding certain values

Body:
valid_numbers = [i for i in range(1111111, 9999997+1) if (i % 10 != 0) and (i % 10 != 8) and (i % 10 != 9) and (i % 21 == 0)]
key = random.choice(valid_numbers)

The first line uses a list comprehension with a conditional if to generate a list of all the numbers that fit your criteria.  Note that the second parameter to range needs to be one greater than the last number you need.  To get the last digit of a number you can use the modulo operator % with 10: i % 10 gives the last decimal digit of i.  Likewise i % 21 == 0 tells you if the number divides evenly by 21.

Once you have that list, it's just a matter of picking a number from the list with random.choice.


问:
How to Extend/Architect the ASP.NET MVC 3 Authorize Attribute to Handle This Scenario
I've been trying to think this answer through and can't find a good solution on how to properly do this.

I've read over these articles:

http://schotime.net/blog/index.php/2009/02/17/custom-authorization-with-aspnet-mvc/

http://geekswithblogs.net/brians/archive/2010/07/08/implementing-a-custom-asp.net-mvc-authorization-filter.aspx

ASP.NET MVC custom authorization

http://davidhayden.com/blog/dave/archive/2009/04/09/CustomAuthorizationASPNETMVCFrameworkAuthorizeAttribute.aspx

Custom Authorize Attribute additional Param?

Thinking maybe the last one is close.

Scenario:

User's create Roles

User's can assign what the Role has access to do.

User's add users to those Roles

User's are also part of a Department.

So in the controller how could I say that a user has access to an action, since I don't know what are the Roles the User's Admin created?

So in logic... let's say I have a Task controller with a "Create", "Details".  The Task has a Department of "Clothing".

Task:

-- TaskID

-- TaskTitle

-- TaskDepartmentID

-- User:

-- UserName

-- Roles

-- Departments

I would somehow associate the "Create" action with "Create Task" ability

I would somehow associate the "Details" action with "View Task Details" ability

The admin would add a new role called "Task Users" and say this role can "Create Tasks"

The admin would also allow this role to "View Task Details"

The admin would turn on "Department Level Security"

Creating:

When the Task Create is called on the controller I would need to make sure the user is in a Role that allows "Create Task". So by default I can't send in the "Roles" allowed into the Authorize Attribute because I don't know them. I somehow need to send in all the Roles the user has and see if a role has access to "Create Tasks"

Viewing with Department Security:

When another user goes to view this task, they may have access to "View Task Details" (which I can figure out however I solve the first issue). However, since the Task is for another department other then the one they are in, I need to deny access.  The user can only "View Task Details" if the Task is part of one of the Department the User is in.

This is what I can't figure out. How to properly extend the AuthorizeAttribute so I can send in a list of Roles via GerRolesForUser since it only accepts a string, and how to identify what Action it's for and then limit security on another level by checking for the Department ID.

Department ID doesn't necessarily have to be cached so maybe I can do that at the controller level.

答:
I had somewhat similar problem and I did not use Authorize attribute.

Instead I decided to to take the different -2 Layout for the Different user .

if the User is Admin then he will go to the different view and if the user is guest he will go to the different view through different layout.


问:
Print all subsets in an array that equal to a given sum recursively
I have to write a code with a two methods that takes an array (non-negative) and a value sum as parameters.
I have to use the methods:

```<code>public static void printSubsetSums(int[] arr, int sum) {

}

public static void printSubsetSums(int[] arr, int sum, int i, String acc)
{

}
</code>```

We are not allowed to add methods or any more parameters for the current methods.
I did something similar that just prints the number of subsets that are from a given array according to a sum. but i'm having a hard time to change it to do this task...
my array is limited to the length of 5.

ecxample:
"Enter 5 numbers to array"
input:1 2 3 4 5
"Enter a number into sum"
input:8
3

why 3? (3,5) , (1,3,4) , (1,2,5)

Thank you for your help!!!

答:
I think you have to take as input an array of numbers , and give the sum and number of integers that can be equal to this sum

In your example :

Enter 5 numbers to array : 1 2 3 4 5

Enter a number into sum : 8 3 ( here i think 3 means it wants only 3 numbers to form 8 , like 1 2 5 and 2 3 5 .. etc )

You can do it in this way :

```<code>public static void printSubsetSums(int[] arr, int sum, int i) {
    // getting all possible sub arrays of a lentgh of i
    ArrayList<int[]> subarrays = new ArrayList<int[]>();
    ArrayList<Integer> array = new ArrayList<Integer>();

    int arrSize = arr.length;
    for (int startPoint = 0; startPoint <arrSize ; startPoint++) {
        for (int grps = startPoint; grps <=arrSize ; grps++) {
            for (int j = startPoint ; j < grps ; j++) {
                int element = arr[j];
                array.add(element);
            }
            int[] tab = new int[array.size()];
            int x = 0;
            for(int n : array) {
                tab[x] = n;
                x++;
            }
            subarrays.add(tab);
            array.clear();

        }
    }
    // calculating the sum of each one of these arrays
    // print the ones that their sum equal the sum given with argument
    for(int[] al : subarrays) {
        if (al.length==3) {
            int sum2 = 0;
            for (int n : al) {
                sum2 = sum2 + n;
                System.out.print(n);
            }
            System.out.print(" = "+sum2);
            if(sum2==sum) { System.out.print(" that is a desired sum"); }
            System.out.println();
        }
    }

}
</code>```

Body:
I have to write a code with a two methods that takes an array (non-negative) and a value sum as parameters.
I have to use the methods:

public static void printSubsetSums(int[] arr, int sum) {

}

public static void printSubsetSums(int[] arr, int sum, int i, String acc)
{

}

We are not allowed to add methods or any more parameters for the current methods.
I did something similar that just prints the number of subsets that are from a given array according to a sum. but i'm having a hard time to change it to do this task...
my array is limited to the length of 5.

ecxample:
"Enter 5 numbers to array"
input:1 2 3 4 5
"Enter a number into sum"
input:8
3

why 3? (3,5) , (1,3,4) , (1,2,5)

Thank you for your help!!!

Body:
I think you have to take as input an array of numbers , and give the sum and number of integers that can be equal to this sum

In your example :

Enter 5 numbers to array : 1 2 3 4 5

Enter a number into sum : 8 3 ( here i think 3 means it wants only 3 numbers to form 8 , like 1 2 5 and 2 3 5 .. etc )

You can do it in this way :

public static void printSubsetSums(int[] arr, int sum, int i) {
    // getting all possible sub arrays of a lentgh of i
    ArrayList<int[]> subarrays = new ArrayList<int[]>();
    ArrayList<Integer> array = new ArrayList<Integer>();

    int arrSize = arr.length;
    for (int startPoint = 0; startPoint <arrSize ; startPoint++) {
        for (int grps = startPoint; grps <=arrSize ; grps++) {
            for (int j = startPoint ; j < grps ; j++) {
                int element = arr[j];
                array.add(element);
            }
            int[] tab = new int[array.size()];
            int x = 0;
            for(int n : array) {
                tab[x] = n;
                x++;
            }
            subarrays.add(tab);
            array.clear();

        }
    }
    // calculating the sum of each one of these arrays
    // print the ones that their sum equal the sum given with argument
    for(int[] al : subarrays) {
        if (al.length==3) {
            int sum2 = 0;
            for (int n : al) {
                sum2 = sum2 + n;
                System.out.print(n);
            }
            System.out.print(" = "+sum2);
            if(sum2==sum) { System.out.print(" that is a desired sum"); }
            System.out.println();
        }
    }

}


问:
Turn off nginx authentication for GraphQL api on Gatsby site
I've been having a hard time with turning off authentication for the GraphQL api. It keeps failing the build. This is what I have now, which I thought was correct.</p>

```<code>location / {
    try_files $uri $uri/ @rewrites;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

location ^~ /api/ {
   auth_basic off;
   fastcgi_read_timeout 1200;

   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

   # below for some setups on php 7.4
   #include snippets/fastcgi-php.conf;
   include /etc/nginx/fastcgi_params;
   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

</code>```

答:
Solution & Update

```<code>location ^~ /api {
    auth_basic off;
    try_files $uri $uri/ /index.php?$args;
}
</code>```

reference:

https://stackoverflow.com/a/62180832/12257950

Turn off nginx authentication for GraphQL api on Gatsby site

I have tried to replicate the issue on my end but working properly.

I use OpenResty and added a header X-reached with more_set_headers (you can use add_header alternatively) in the /api/ location block.

You can try with the same and see if the request actually reached the correct location block.

This is my Nginx configuration

```<code>location / {
    try_files $uri $uri/ @rewrites;
    auth_basic "restricted";
    auth_basic_user_file /usr/local/openresty/nginx/conf/conf.d/.htpasswd;
}

location ^~ /api/ {
    auth_basic off;
    try_files $uri $uri/ /index.php?$args;
    more_set_headers 'X-reached true';
}

location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}
</code>```

You can check the header in the response with following command

 curl -XGET -IL https://site-name.tld/api/path
```

or you can use Network tab in the browser's Inspect.

2.Check that some redirection is not happening.

Body:
I've been having a hard time with turning off authentication for the GraphQL api. It keeps failing the build. This is what I have now, which I thought was correct.

location / {
    try_files $uri $uri/ @rewrites;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

location ^~ /api/ {
   auth_basic off;
   fastcgi_read_timeout 1200;

   fastcgi_split_path_info ^(.+\.php)(/.+)$;
   fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

   # below for some setups on php 7.4
   #include snippets/fastcgi-php.conf;
   include /etc/nginx/fastcgi_params;
   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

Body:
Solution & Update

location ^~ /api {
    auth_basic off;
    try_files $uri $uri/ /index.php?$args;
}

reference:

https://stackoverflow.com/a/62180832/12257950

Turn off nginx authentication for GraphQL api on Gatsby site

I have tried to replicate the issue on my end but working properly.

I use OpenResty and added a header X-reached with more_set_headers (you can use add_header alternatively) in the /api/ location block.

You can try with the same and see if the request actually reached the correct location block.

This is my Nginx configuration

location / {
    try_files $uri $uri/ @rewrites;
    auth_basic "restricted";
    auth_basic_user_file /usr/local/openresty/nginx/conf/conf.d/.htpasswd;
}

location ^~ /api/ {
    auth_basic off;
    try_files $uri $uri/ /index.php?$args;
    more_set_headers 'X-reached true';
}

location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

You can check the header in the response with following command

 curl -XGET -IL https://site-name.tld/api/path

or you can use Network tab in the browser's Inspect.

2.Check that some redirection is not happening.


问:
Trim Powershell OutPut
Requirement is to trim the Output. Retain only the output quoted within double quotes from Name and remove/avoid the earlier lines/characters

From:

```<code>$R.Output = \\GBVServer1\root\cimv2:Win32_Group.Domain="Contoso",Name="Domain Users"

$R.Output = \\GBVServer1\root\cimv2:Win32_SystemAccount.Domain="GBVServer1",Name="INTERACTIVE"
</code>```

To:

```<code>$R.Output = Domain Users

$R.Output = INTERACTIVE
</code>```

Could somebody assist with the powershell switch to be used?

答:
You can do this with regex to capture only the Name part between the quotes for these strings:

```<code>$regex = [regex]'(?i)Name="([^,]+)"'

$string = '\\GBVServer1\root\cimv2:Win32_Group.Domain="Contoso",Name="Domain Users"'
$R.Output = $regex.Match($string).Groups[1].Value  # --> Domain Users

$string = '\\GBVServer1\root\cimv2:Win32_SystemAccount.Domain="GBVServer1",Name="INTERACTIVE"'
$R.Output = $regex.Match($string).Groups[1].Value  # --> INTERACTIVE
</code>```

Regex details:

```
Name="      Match the characters “Name="” literally
(           Match the regular expression below and capture its match into backreference number 1
   [^,]     Match any character that is NOT a “,”
      +     Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
"           Match the character “"” literally
```

The (?i) makes the match case-insensitive

Title: Trim Powershell OutPut

Body:
Requirement is to trim the Output. Retain only the output quoted within double quotes from Name and remove/avoid the earlier lines/characters

From:

$R.Output = \\GBVServer1\root\cimv2:Win32_Group.Domain="Contoso",Name="Domain Users"

$R.Output = \\GBVServer1\root\cimv2:Win32_SystemAccount.Domain="GBVServer1",Name="INTERACTIVE"

To:

$R.Output = Domain Users

$R.Output = INTERACTIVE

Could somebody assist with the powershell switch to be used?

Body:
You can do this with regex to capture only the Name part between the quotes for these strings:

$regex = [regex]'(?i)Name="([^,]+)"'

$string = '\\GBVServer1\root\cimv2:Win32_Group.Domain="Contoso",Name="Domain Users"'
$R.Output = $regex.Match($string).Groups[1].Value  # --> Domain Users

$string = '\\GBVServer1\root\cimv2:Win32_SystemAccount.Domain="GBVServer1",Name="INTERACTIVE"'
$R.Output = $regex.Match($string).Groups[1].Value  # --> INTERACTIVE

Regex details:

Name="      Match the characters “Name="” literally
(           Match the regular expression below and capture its match into backreference number 1
   [^,]     Match any character that is NOT a “,”
      +     Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
"           Match the character “"” literally

The (?i) makes the match case-insensitive


问:
How do I trigger a call to dispatch using React Hooks?
I have a save function in a component that makes some calls to an API and changes my local state based on the response. I then want to dispatch an action once AND ONLY ONCE these calls to setState are complete e.g.

```<code>const [myData, setMyData] = useState([{id: 0, name: "Alex"}]);

const save = async () => {

    if (someCondition) {
        let response = await axios.get("/someroute");
        if (response.status === 200) {
            setMyData([...myData, response.data])])
        }
    }

    if (someOtherCondition) {
        let response2 = await axios.get("/someotherroute");
        if (response2.status === 200) {
            setMyData([...myData, response2.data])])
        }
    }

    dispatch(myAction(myData));
}
</code>```

Now I know that useEffect should be the way to go about this. e.g.

```<code>useEffect(() => {
    dispatch(myAction(myData));
}, [myData]);
</code>```

however i'm changing myData at other places in the component, and I only want to dispatch the action once save() has been called and the setMyData calls have finished. I can't think of a condition to check for in useEffect() except maybe adding some kind of flag to myData, like an object saying "Ready to save", but it feels like there should be a simpler way.

Massively appreciate any help on this one!

答:
It's looks like you need to use useReduce instead and then you are able to detect when any of the props change with the useEffect:

```<code>
const initialState = {
  id: null,
  name: null,
  ...
}
const [state, dispatch] = useReducer((state, action) => {
  switch (action.type) {
    case 'CHANGE-NAME':
      return { ...state, name: action.value }
    default:
      throw new Error('Type not defined')
  }
}, initialState)

useEffect(() => {
  // Notify changes!!
}, [state.name]);

...
const myFun = async () {
  // do something
  dispatch({ type: 'CHANGE-NAME', value: 'Hello world' })
}
</code>```

Also you can add other props to your initial state, for example if you need a specific flag to detect an action once :)

Regards

Body:
I have a save function in a component that makes some calls to an API and changes my local state based on the response. I then want to dispatch an action once AND ONLY ONCE these calls to setState are complete e.g.

const [myData, setMyData] = useState([{id: 0, name: "Alex"}]);

const save = async () => {

    if (someCondition) {
        let response = await axios.get("/someroute");
        if (response.status === 200) {
            setMyData([...myData, response.data])])
        }
    }

    if (someOtherCondition) {
        let response2 = await axios.get("/someotherroute");
        if (response2.status === 200) {
            setMyData([...myData, response2.data])])
        }
    }

    dispatch(myAction(myData));
}

Now I know that useEffect should be the way to go about this. e.g.

useEffect(() => {
    dispatch(myAction(myData));
}, [myData]);

however i'm changing myData at other places in the component, and I only want to dispatch the action once save() has been called and the setMyData calls have finished. I can't think of a condition to check for in useEffect() except maybe adding some kind of flag to myData, like an object saying "Ready to save", but it feels like there should be a simpler way.

Massively appreciate any help on this one!

Body:
It's looks like you need to use useReduce instead and then you are able to detect when any of the props change with the useEffect:

const initialState = {
  id: null,
  name: null,
  ...
}
const [state, dispatch] = useReducer((state, action) => {
  switch (action.type) {
    case 'CHANGE-NAME':
      return { ...state, name: action.value }
    default:
      throw new Error('Type not defined')
  }
}, initialState)

useEffect(() => {
  // Notify changes!!
}, [state.name]);

...
const myFun = async () {
  // do something
  dispatch({ type: 'CHANGE-NAME', value: 'Hello world' })
}

Also you can add other props to your initial state, for example if you need a specific flag to detect an action once :)

Regards


问:
Performing side effects on Publisher
I'm trying to perform side effect on Publisher, and I can't find any operator which will allow me to do something like this. To be precise, I'm looking for a concept similar to RxSwift's do(on:).

Here's what I'm trying to do.
I'm writing a reactive wrapper for a delegate provided by a 3rd party SDK. It's and SDK for interacting with BLE devices. I have methods like startScanning and stopScanning and what I want to achieve is to react to signals and call stopScanning as a side effect of any error or complete events. So far, I have something like this:

newDeviceFoundPublisher
            .timeout(.seconds(timeout), scheduler: DispatchQueue.global())
            .eraseToAnyPublisher()
```

<p>and what I want to achieve is something like:</p>

<pre class="lang-swift prettyprint-override"><code>newDeviceFoundPublisher
            .timeout(.seconds(timeout), scheduler: DispatchQueue.global())
            .doOnError {
                manager.stopScanning()
            }
            .doOnComplete {
                manager.stopScanning()
            }
            .eraseToAnyPublisher()
</code>```

Is there already something like this or maybe I'm missing something, and there's something in Combine I can use and get the result?

答:
You might be looking for the .handleEvents operator. You can implement it with any of five different parameters; they are all optional, so implement just those you need. Both an error and a completion would count as receiveCompletion:.

Note that the error will still flow on down the pipeline if you don't catch it! (The completion will flow down the pipeline in any case, and I don't think you can stop it.)

Title: Performing side effects on Publisher

Body:
I'm trying to perform side effect on Publisher, and I can't find any operator which will allow me to do something like this. To be precise, I'm looking for a concept similar to RxSwift's do(on:).

Here's what I'm trying to do.
I'm writing a reactive wrapper for a delegate provided by a 3rd party SDK. It's and SDK for interacting with BLE devices. I have methods like startScanning and stopScanning and what I want to achieve is to react to signals and call stopScanning as a side effect of any error or complete events. So far, I have something like this:

newDeviceFoundPublisher
            .timeout(.seconds(timeout), scheduler: DispatchQueue.global())
            .eraseToAnyPublisher()

and what I want to achieve is something like:

newDeviceFoundPublisher
            .timeout(.seconds(timeout), scheduler: DispatchQueue.global())
            .doOnError {
                manager.stopScanning()
            }
            .doOnComplete {
                manager.stopScanning()
            }
            .eraseToAnyPublisher()

Is there already something like this or maybe I'm missing something, and there's something in Combine I can use and get the result?


问:
Is there a way to iterate over FireDAC's TFDParams using Delphi's for .. in .. do?
With Delphi 10.2 (Tokyo), I just want to do something as simple as:

```<code>function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TFDParam;
begin
  cSQL := qry.SQL.Text;
  for oParam in qry.Params do
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  Result := cSQL;
end;
</code>```

But I always get the error message:

[dcc32 Error] DTUtilBD.pas(3115): E2010 Incompatible types: 'TFDParam' and 'TCollectionItem'

Is there a way of doing it?

答:
TFDQuery.Params is a TFDParams, which can be iterated with a for..in loop as it has a public GetEnumerator() method.  However, that method is inherited from TCollection to iterate TCollectionItem items, so it is not specialized for TFDParam items (feel free to file a bug report about that oversight).

As such, when the loop iteration tries to assign the enumerator's Current property to your oParam variable, it fails to compile because a TCollectionItem cannot be assigned to a TFDParam.  Which is exactly what the compiler error is complaining about.

Your code basically gets compiled as-if it had been written like this:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TFDParam;
  cEnum: TCollectionEnumerator;
begin
  cSQL := qry.SQL.Text;
  //for oParam in qry.Params do
  cEnum := qry.Params.GetEnumerator;
  while cEnum.MoveNext do
  begin
    oParam := cEnum.Current; // <-- ERROR HERE - cEnum.Current is TCollectionItem!
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;
```

<p>To fix this, you need to change your <code>oParam</code> variable to be a <code>TCollectionItem</code> instead of a <code>TFDParam</code>.  You will just have to type-cast it when you want to access any <code>TFDParam</code>-specific members, eg:</p>

<pre class="lang-pascal prettyprint-override"><code>function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TCollectionItem;
begin
  cSQL := qry.SQL.Text;
  for oParam in qry.Params do
    cSQL := cSQL.Replace(TFDParam(oParam).Name, TFDParam(oParam).Value);
  Result := cSQL;
end;
</code>```

Alternatively:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oItem: TCollectionItem;
  oParam: TFDParam;
begin
  cSQL := qry.SQL.Text;
  for oItem in qry.Params do
  begin
    oParam := TFDParam(oItem);
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;
```

<p><strong>UPDATE</strong>: Alternatively, if you want to avoid type-casting manually, you can use <code>absolute</code>:</p>

<pre class="lang-pascal prettyprint-override"><code>function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oItem: TCollectionItem;
  oParam: TFDParam absolute oItem;
begin
  cSQL := qry.SQL.Text;
  for oItem in qry.Params do
  begin
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;
</code>```

Body:
With Delphi 10.2 (Tokyo), I just want to do something as simple as:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TFDParam;
begin
  cSQL := qry.SQL.Text;
  for oParam in qry.Params do
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  Result := cSQL;
end;

But I always get the error message:

[dcc32 Error] DTUtilBD.pas(3115): E2010 Incompatible types: 'TFDParam' and 'TCollectionItem'

Is there a way of doing it?

Body:
TFDQuery.Params is a TFDParams, which can be iterated with a for..in loop as it has a public GetEnumerator() method.  However, that method is inherited from TCollection to iterate TCollectionItem items, so it is not specialized for TFDParam items (feel free to file a bug report about that oversight).

As such, when the loop iteration tries to assign the enumerator's Current property to your oParam variable, it fails to compile because a TCollectionItem cannot be assigned to a TFDParam.  Which is exactly what the compiler error is complaining about.

Your code basically gets compiled as-if it had been written like this:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TFDParam;
  cEnum: TCollectionEnumerator;
begin
  cSQL := qry.SQL.Text;
  //for oParam in qry.Params do
  cEnum := qry.Params.GetEnumerator;
  while cEnum.MoveNext do
  begin
    oParam := cEnum.Current; // <-- ERROR HERE - cEnum.Current is TCollectionItem!
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;

To fix this, you need to change your oParam variable to be a TCollectionItem instead of a TFDParam.  You will just have to type-cast it when you want to access any TFDParam-specific members, eg:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oParam: TCollectionItem;
begin
  cSQL := qry.SQL.Text;
  for oParam in qry.Params do
    cSQL := cSQL.Replace(TFDParam(oParam).Name, TFDParam(oParam).Value);
  Result := cSQL;
end;

Alternatively:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oItem: TCollectionItem;
  oParam: TFDParam;
begin
  cSQL := qry.SQL.Text;
  for oItem in qry.Params do
  begin
    oParam := TFDParam(oItem);
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;

UPDATE: Alternatively, if you want to avoid type-casting manually, you can use absolute:

function ShowFinalSQL(const qry: TFDQuery): String;
var
  cSQL: String;
  oItem: TCollectionItem;
  oParam: TFDParam absolute oItem;
begin
  cSQL := qry.SQL.Text;
  for oItem in qry.Params do
  begin
    cSQL := cSQL.Replace(oParam.Name, oParam.Value);
  end;
  Result := cSQL;
end;


问:
unable to pass test cases in codewar
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. A "Avengers" ticket costs 25 dollars.

Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.

Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Return YES, if Vasya can sell a ticket to each person and give the change. Otherwise return NO.

Eg.

```<code>Line.Tickets(new int[] {25, 25, 50}) // => YES
</code>```

I was able to pass 10 test cases out of 11 but for 1 test case it showing that my result is wrong.

Say,
Input=>Line.Tickets(new int[] {25,50,25,100})
My code's output=

NO

If first person has 25$ bill->count25=1 and count50=0 ,if second person has 50 dollar bill->count50=1 and count25=0,if third person has 25$ bill->count50=1 and count25=1,if fourth person have 100$bill->count50=0 and count25=0

```<code>public class Line {
    public static String Tickets(int[] peopleInLine) {
        int count25 = 0;
        int count50 = 0;
        for (int i = 0; i < peopleInLine.length; i++) {
            if (peopleInLine[i] == 100) {
                if (count25 == 1 && count50 > 0) {
                    count25 = count25 - 1;
                    count50 = count50 - 1;
                }

                if (count25 >= 3) {
                    count25 = count25 - 3;
                } else {
                    return "NO";
                }
            }

            if (peopleInLine[i] == 25) {
                count25 = count25 + 1;
            }

            if (peopleInLine[i] == 50) {
                count50 = count50 + 1;
                count25 = count25 - 1;
                if (count25 < 0) {
                    return "NO";
                }
            }
        }
        return "YES";
    }
}
</code>```

答:
```<code>private static String checkTicketChangePossible(int[] ticketPrices){
  String returnValue = "YES";
  int bill_25 = 0;
  int bill_50 = 0;

  for(int i= 0; i< ticketPrices.length; i++){
      if(ticketPrices[i] == 25){
          bill_25 += 1;
      }
      if(ticketPrices[i] == 50){
          bill_25 -= 1;
          bill_50 += 1;
      }
      if(ticketPrices[i] == 100){
          if(bill_50 == 0 && bill_25 >= 3){
            bill_25 -= 3;
          }else{
            bill_25 -= 1; bill_50 -= 1;
          }
      }

      if(bill_25 < 0 || bill_50 <0){
         returnValue = "NO";
         break;
      }

  }
  return returnValue;
}
</code>```

Title: unable to pass test cases in codewar

Body:
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. A "Avengers" ticket costs 25 dollars.

Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.

Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Return YES, if Vasya can sell a ticket to each person and give the change. Otherwise return NO.

Eg.

Line.Tickets(new int[] {25, 25, 50}) // => YES

I was able to pass 10 test cases out of 11 but for 1 test case it showing that my result is wrong.

Say,
Input=>Line.Tickets(new int[] {25,50,25,100})
My code's output=

NO

If first person has 25$ bill->count25=1 and count50=0 ,if second person has 50 dollar bill->count50=1 and count25=0,if third person has 25$ bill->count50=1 and count25=1,if fourth person have 100$bill->count50=0 and count25=0

public class Line {
    public static String Tickets(int[] peopleInLine) {
        int count25 = 0;
        int count50 = 0;
        for (int i = 0; i < peopleInLine.length; i++) {
            if (peopleInLine[i] == 100) {
                if (count25 == 1 && count50 > 0) {
                    count25 = count25 - 1;
                    count50 = count50 - 1;
                }

                if (count25 >= 3) {
                    count25 = count25 - 3;
                } else {
                    return "NO";
                }
            }

            if (peopleInLine[i] == 25) {
                count25 = count25 + 1;
            }

            if (peopleInLine[i] == 50) {
                count50 = count50 + 1;
                count25 = count25 - 1;
                if (count25 < 0) {
                    return "NO";
                }
            }
        }
        return "YES";
    }
}