views:

445

answers:

6

My program has a trouble: When GC perform garbage collection,my program always crashes at a function,which is called by main flow several times before

crashing and the first line of this function is GC.Collect().The function main action is sending some bytes to serial port and receiving some bytes from the

same serial port( Both sending and received bytes are below 256 bytes) each time.GC.Collect() calling is for locating the crashing point,it'll be removed in

release edition.

I don't know the exact reason,but I know the exact function where the program crash.So,I have to disable GC or pause GC during the function calling.

How can I do it ?

The kindly response will be appreciated!

sincerely, jizhiguo

email: [email protected]

PS:

Environment: winxp(sp3),vs2005,.net 2.0,c#,oracle 10g

The following is my windbg tracing info : *Note: the namespace of IFDMgr and NSIISys is my own creation.

--------------------------WinDbg  tracing info --------------------------

Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

*** wait with pending attach
Symbol search path is: SRV*d:\websymbols*http://msdl.microsoft.com/download/symbols;D:\jizg\NSIISys\bin\Debug;D:\Symbols
Executable search path is: 
ModLoad: 00400000 00512000   D:\jizg\NSIISys\bin\Debug\NSIISys.exe
ModLoad: 7c920000 7c9b6000   C:\WINDOWS\system32\ntdll.dll
ModLoad: 79000000 79046000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 7c800000 7c91e000   C:\WINDOWS\system32\KERNEL32.dll
ModLoad: 77da0000 77e49000   C:\WINDOWS\system32\ADVAPI32.dll
ModLoad: 77e50000 77ee2000   C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77fc0000 77fd1000   C:\WINDOWS\system32\Secur32.dll
ModLoad: 77f40000 77fb6000   C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 77ef0000 77f39000   C:\WINDOWS\system32\GDI32.dll
ModLoad: 77d10000 77da0000   C:\WINDOWS\system32\USER32.dll
ModLoad: 77be0000 77c38000   C:\WINDOWS\system32\msvcrt.dll
ModLoad: 76300000 7631d000   C:\WINDOWS\system32\IMM32.DLL
ModLoad: 62c20000 62c29000   C:\WINDOWS\system32\LPK.DLL
ModLoad: 73fa0000 7400b000   C:\WINDOWS\system32\USP10.dll
ModLoad: 79e70000 7a400000   C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
ModLoad: 78130000 781cb000   C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989\MSVCR80.dll
ModLoad: 7d590000 7dd84000   C:\WINDOWS\system32\shell32.dll
ModLoad: 77180000 77283000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll
ModLoad: 5d170000 5d20a000   C:\WINDOWS\system32\comctl32.dll
ModLoad: 790c0000 79bb7000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll
ModLoad: 76990000 76acd000   C:\WINDOWS\system32\ole32.dll
ModLoad: 5adc0000 5adf7000   C:\WINDOWS\system32\uxtheme.dll
ModLoad: 10000000 1002f000   C:\Program Files\360safe\safemon\safemon.dll
ModLoad: 770f0000 7717b000   C:\WINDOWS\system32\OLEAUT32.dll
ModLoad: 3e410000 3e4f6000   C:\WINDOWS\system32\WININET.dll
ModLoad: 00df0000 00df9000   C:\WINDOWS\system32\Normaliz.dll
ModLoad: 43ce0000 43e12000   C:\WINDOWS\system32\urlmon.dll
ModLoad: 3eab0000 3ec98000   C:\WINDOWS\system32\iertutil.dll
ModLoad: 76bc0000 76bcb000   C:\WINDOWS\system32\PSAPI.DLL
ModLoad: 71a20000 71a37000   C:\WINDOWS\system32\WS2_32.dll
ModLoad: 71a10000 71a18000   C:\WINDOWS\system32\WS2HELP.dll
ModLoad: 77bd0000 77bd8000   C:\WINDOWS\system32\VERSION.dll
ModLoad: 74680000 746cc000   C:\WINDOWS\system32\MSCTF.dll
ModLoad: 79060000 790bb000   C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll
ModLoad: 7a440000 7abc5000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\80978a322d7dd39f0a71be1251ae395a\System.ni.dll
ModLoad: 7ade0000 7af68000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\3da96ee075bab9202626ae44c18d226c\System.Drawing.ni.dll
ModLoad: 7afd0000 7bbae000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32

\System.Windows.Forms\63406259e94d5c0ff5b79401dfe113ce\System.Windows.Forms.ni.dll
ModLoad: 76d70000 76d92000   C:\WINDOWS\system32\apphelp.dll
ModLoad: 73640000 7366e000   C:\WINDOWS\system32\msctfime.ime
ModLoad: 4ae90000 4b03b000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.6001.22319_x-ww_f0b4c2df\gdiplus.dll
ModLoad: 03900000 03e49000   C:\WINDOWS\system32\xpsp2res.dll
ModLoad: 03810000 0381c000   D:\jizg\NSIISys\bin\Debug\CoreControl.dll
ModLoad: 041b0000 041f8000   C:\WINDOWS\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_zh-CHS_b77a5c561934e089\mscorlib.resources.dll
ModLoad: 040f0000 040f8000   D:\jizg\NSIISys\bin\Debug\DBLibrary.dll
ModLoad: 04190000 0419e000   D:\jizg\NSIISys\bin\Debug\CRWOperator.dll
ModLoad: 637a0000 63cd6000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\773a9786013451d3baaeff003dc4230f\System.Xml.ni.dll
ModLoad: 64890000 64981000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\b82c00e2d24305ad6cb08556e3779b75

\System.Configuration.ni.dll
ModLoad: 68000000 68036000   C:\WINDOWS\system32\rsaenh.dll
ModLoad: 76750000 76759000   C:\WINDOWS\system32\shfolder.dll
ModLoad: 65150000 657a3000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Data\c70731047b0022638b3f9fb158948a03\System.Data.ni.dll
ModLoad: 64e70000 65144000   C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll
ModLoad: 765e0000 76673000   C:\WINDOWS\system32\CRYPT32.dll
ModLoad: 76db0000 76dc2000   C:\WINDOWS\system32\MSASN1.dll
ModLoad: 67af0000 67b8c000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Transactions\5a555c9ae6984c40157cf940bb519f7c\System.Transactions.ni.dll
ModLoad: 67aa0000 67ae3000   C:\WINDOWS\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll
ModLoad: 75e00000 75eae000   C:\WINDOWS\system32\sxs.dll
ModLoad: 76fa0000 7701f000   C:\WINDOWS\system32\CLBCATQ.DLL
ModLoad: 77020000 770ba000   C:\WINDOWS\system32\COMRes.dll
ModLoad: 72d70000 72de7000   C:\Program Files\Common Files\system\ole db\oledb32.dll
ModLoad: 75b50000 75b75000   C:\WINDOWS\system32\MSDART.DLL
ModLoad: 76320000 76367000   C:\WINDOWS\system32\comdlg32.dll
ModLoad: 74fa0000 74fb1000   C:\Program Files\Common Files\system\ole db\OLEDB32R.DLL
ModLoad: 1b570000 1b5c4000   C:\WINDOWS\system32\msjetoledb40.dll
ModLoad: 1b000000 1b170000   C:\WINDOWS\system32\msjet40.dll
ModLoad: 1b5d0000 1b665000   C:\WINDOWS\system32\mswstr10.dll
ModLoad: 1b2c0000 1b2cd000   C:\WINDOWS\system32\msjter40.dll
ModLoad: 1b2d0000 1b2f6000   C:\WINDOWS\system32\MSJINT40.DLL
ModLoad: 75690000 757cc000   C:\WINDOWS\system32\comsvcs.dll
ModLoad: 75090000 750a4000   C:\WINDOWS\system32\colbact.DLL
ModLoad: 75050000 75063000   C:\WINDOWS\system32\MTXCLU.DLL
ModLoad: 71a40000 71a4b000   C:\WINDOWS\system32\WSOCK32.dll
ModLoad: 5fdd0000 5fe25000   C:\WINDOWS\system32\NETAPI32.dll
ModLoad: 762a0000 762b2000   C:\WINDOWS\system32\CLUSAPI.DLL
ModLoad: 75010000 75022000   C:\WINDOWS\system32\RESUTILS.DLL
ModLoad: 759d0000 75a7f000   C:\WINDOWS\system32\USERENV.dll
ModLoad: 673f0000 6748d000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.EnterpriseSe#\4267bd908175603006c6c90bb5d900c7

\System.EnterpriseServices.ni.dll
ModLoad: 09ce0000 09d28000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.EnterpriseSe#\4267bd908175603006c6c90bb5d900c7

\System.EnterpriseServices.Wrapper.dll
ModLoad: 09d30000 09d50000   C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll
ModLoad: 1b800000 1b83a000   C:\WINDOWS\system32\msjtes40.dll
ModLoad: 0f9a0000 0f9ab000   C:\WINDOWS\system32\VBAJET32.DLL
ModLoad: 0f9c0000 0fa22000   C:\WINDOWS\system32\expsrv.dll
ModLoad: 099a0000 099a8000   D:\jizg\NSIISys\bin\Debug\FileMgr.dll
ModLoad: 09ae0000 09aea000   D:\jizg\NSIISys\bin\Debug\Log.dll
ModLoad: 09af0000 09b08000   D:\jizg\NSIISys\bin\Debug\IFDMgr.dll
ModLoad: 09b90000 09b9a000   D:\jizg\NSIISys\bin\Debug\SysUtilities.dll
ModLoad: 719c0000 719fe000   C:\WINDOWS\system32\mswsock.dll
ModLoad: 60fd0000 61025000   C:\WINDOWS\system32\hnetcfg.dll
ModLoad: 71a00000 71a08000   C:\WINDOWS\System32\wshtcpip.dll
ModLoad: 09c20000 09c29000   D:\jizg\NSIISys\bin\Debug\JC_6200D.dll
ModLoad: 73d30000 73e2e000   C:\WINDOWS\system32\MFC42.DLL
ModLoad: 61be0000 61bed000   C:\WINDOWS\system32\MFC42LOC.DLL
ModLoad: 5e430000 5e5d6000   C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Microsoft.VisualBas#\1c86afc399d0fdd8e069266ffbe748d1

\Microsoft.VisualBasic.ni.dll
(1f0.b64): Break instruction exception - code 80000003 (first chance)
eax=7ffdb000 ebx=00000001 ecx=00000002 edx=00000003 esi=00000004 edi=00000005
eip=7c92120e esp=0ac9ffcc ebp=0ac9fff4 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=0038  gs=0000             efl=00000246
ntdll!DbgBreakPoint:
7c92120e cc              int     3
Missing image name, possible paged-out or corrupt data.
0:014> kbn
 # ChildEBP RetAddr  Args to Child              
00 0ac9ffc8 7c971e40 00000005 00000004 00000001 ntdll!DbgBreakPoint
01 0ac9fff4 00000000 00000000 00000000 00000000 ntdll!DbgUiRemoteBreakin+0x2d
0:014> .loadby sos mscorwks
0:014> !clrstack
OS Thread Id: 0xb64 (14)
Unable to walk the managed stack. The current thread is likely not a 
managed thread. You can run !threads to get a list of managed threads in
the process
0:014> !threads
ThreadCount: 7
UnstartedThread: 0
BackgroundThread: 6
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
                                      PreEmptive   GC Alloc           Lock
       ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception
   0    1  f98 0015b260      6020 Enabled  0155a190:0155acf8 001634d8     0 STA
   2    2  8f8 00165038      b220 Enabled  00000000:00000000 001634d8     0 MTA (Finalizer)
   7    3  268 001a11a8   200b220 Enabled  0148b480:0148c134 001634d8     0 MTA
   8    4  a6c 001b6880    80a220 Enabled  00000000:00000000 001634d8     0 MTA (Threadpool Completion Port)
  10    5  aec 001d9138   200b220 Enabled  00000000:00000000 001634d8     0 MTA
  11    6  e9c 001bc838   200b220 Enabled  014a49f8:014a6134 001634d8     0 MTA
  12    7  818 0022e0e8   200b220 Enabled  01554210:01554cf8 001634d8     0 MTA
0:014> g
ModLoad: 0ada0000 0adca000   D:\jizg\NSIISys\bin\Debug\AghwLib_N.dll
ModLoad: 5f400000 5f4e5000   C:\WINDOWS\system32\MFC42D.DLL
ModLoad: 10200000 10264000   C:\WINDOWS\system32\MSVCRTD.dll
ModLoad: 65860000 658db000   System.Data.OracleClient.dll
ModLoad: 65860000 658db000   C:\WINDOWS\assembly\GAC_32\System.Data.OracleClient\2.0.0.0__b77a5c561934e089\System.Data.OracleClient.dll
ModLoad: 0b060000 0b0b7000   D:\oracle\product\10.2.0\db_1\bin\oci.dll
ModLoad: 7c340000 7c396000   C:\WINDOWS\system32\MSVCR71.dll
ModLoad: 61c20000 61e72000   D:\oracle\product\10.2.0\db_1\bin\OraClient10.Dll
ModLoad: 60870000 60953000   D:\oracle\product\10.2.0\db_1\bin\oracore10.dll
ModLoad: 60a80000 60b44000   D:\oracle\product\10.2.0\db_1\bin\oranls10.dll
ModLoad: 63690000 636a8000   D:\oracle\product\10.2.0\db_1\bin\oraunls10.dll
ModLoad: 60eb0000 60eb7000   D:\oracle\product\10.2.0\db_1\bin\orauts.dll
ModLoad: 76b10000 76b3a000   C:\WINDOWS\system32\WINMM.dll
ModLoad: 636b0000 636b6000   D:\oracle\product\10.2.0\db_1\bin\oravsn10.dll
ModLoad: 0b0c0000 0b1b2000   D:\oracle\product\10.2.0\db_1\bin\oracommon10.dll
ModLoad: 60300000 60857000   D:\oracle\product\10.2.0\db_1\bin\orageneric10.dll
ModLoad: 63430000 63457000   D:\oracle\product\10.2.0\db_1\bin\orasnls10.dll
ModLoad: 0b1c0000 0b320000   D:\oracle\product\10.2.0\db_1\bin\oraxml10.dll
ModLoad: 0b010000 0b021000   C:\WINDOWS\system32\MSVCIRT.dll
ModLoad: 60960000 60a6d000   D:\oracle\product\10.2.0\db_1\bin\oran10.dll
ModLoad: 62740000 6277d000   D:\oracle\product\10.2.0\db_1\bin\oranl10.dll
ModLoad: 62790000 627a7000   D:\oracle\product\10.2.0\db_1\bin\oranldap10.dll
ModLoad: 627f0000 628f9000   D:\oracle\product\10.2.0\db_1\bin\orannzsbb10.dll
ModLoad: 62530000 62583000   D:\oracle\product\10.2.0\db_1\bin\oraldapclnt10.dll
ModLoad: 62670000 6268b000   D:\oracle\product\10.2.0\db_1\bin\orancrypt10.dll
ModLoad: 62920000 6296c000   D:\oracle\product\10.2.0\db_1\bin\oranro10.dll
ModLoad: 626b0000 626b7000   D:\oracle\product\10.2.0\db_1\bin\oranhost10.dll
ModLoad: 62660000 62666000   D:\oracle\product\10.2.0\db_1\bin\orancds10.dll
ModLoad: 629c0000 629c8000   D:\oracle\product\10.2.0\db_1\bin\orantns10.dll
ModLoad: 60b50000 60ea8000   D:\oracle\product\10.2.0\db_1\bin\orapls10.dll
ModLoad: 0aff0000 0aff9000   D:\oracle\product\10.2.0\db_1\bin\oraslax10.dll
ModLoad: 63080000 63284000   D:\oracle\product\10.2.0\db_1\bin\oraplp10.dll
ModLoad: 61ed0000 61f5b000   D:\oracle\product\10.2.0\db_1\bin\orahasgen10.dll
ModLoad: 62ab0000 62b1a000   D:\oracle\product\10.2.0\db_1\bin\oraocr10.dll
ModLoad: 62b20000 62b60000   D:\oracle\product\10.2.0\db_1\bin\oraocrb10.dll
ModLoad: 62980000 62990000   D:\oracle\product\10.2.0\db_1\bin\orantcp10.dll
ModLoad: 0b320000 0b3ba000   D:\oracle\product\10.2.0\db_1\bin\orasql10.dll
ModLoad: 0b880000 0b896000   D:\jizg\NSIISys\bin\Debug\Crwicc.dll
(1f0.e9c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=00ba1020 ecx=000146b1 edx=0146b198 esi=013c0000 edi=00000155
eip=79f9423a esp=0aa8ec5c ebp=0aa8ed3c iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210246
mscorwks!WKS::gc_heap::plan_phase+0x5c3:
Missing image name, possible paged-out or corrupt data.
79f9423a f70000000080    test    dword ptr [eax],80000000h ds:0023:00000000=????????
*** WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll
0:011> kbn
 # ChildEBP RetAddr  Args to Child              
00 0aa8ed3c 79f92d5b 00000002 7a3b8ae0 00000001 mscorwks!WKS::gc_heap::plan_phase+0x5c3
01 0aa8ed5c 79f932d5 00000000 7a3b8bc8 00080101 mscorwks!WKS::gc_heap::gc1+0x6e
02 0aa8ed70 79f92fea 00000002 00000001 001bc838 mscorwks!WKS::gc_heap::garbage_collect+0x253
03 0aa8ed9c 79f3d2a9 00000002 00000000 0aa8edcc mscorwks!WKS::GCHeap::GarbageCollectGeneration+0x1a9
04 0aa8edac 79f3d2e5 00000002 00000000 001bc838 mscorwks!WKS::GCHeap::GarbageCollectTry+0x33
05 0aa8edcc 79f3d1a4 ffffffff 00000000 00000000 mscorwks!WKS::GCHeap::GarbageCollect+0x67
06 0aa8ee78 79777d16 09bb99aa 09bb98b8 00e95117 mscorwks!GCInterface::CollectGeneration+0xaa
07 0aa8efbc 79e96c8c 655f10e0 0aa8f028 0aa8f010 mscorlib_ni+0x6b7d16
08 0aa8efdc 79eb4afa 79eb4b13 01453830 01453830 mscorwks!MethodDescCallSite::Call_RetI4+0x1c
09 0aa8f0dc 00000000 00000000 00000000 00000000 mscorwks!SafeHandle::RunReleaseMethod+0x89
0:011> !clrstack
OS Thread Id: 0xe9c (11)
ESP       EIP     
0aa8ee28 79f9423a [HelperMethodFrame: 0aa8ee28] System.GC.nativeCollectGeneration(Int32, Int32)
0aa8ee80 79777d16 System.GC.Collect()
0aa8ee84 09bb99aa IFDMgr.ArtcCardGeniusI200Mgr.ExecCmd(System.String, Byte[] ByRef, Int32)
0aa8ef8c 09bb990f IFDMgr.ArtcCardGeniusI200Mgr.IFDMgr.IIFDMgr.ExecCmd(System.String, System.String ByRef, Int32)
0aa8efc0 0b00b4f7 NSIISys.CardMachineForm.InitDF(System.String, CPUCardKit.ICPUCardOperator, CoreControl.DFInfo)
0aa8f410 0b0087ad NSIISys.CardMachineForm.InitCard()
0aa8f5a4 09bb8d5b NSIISys.CardMachineForm.IssueCard()
0aa8f684 09bb8952 NSIISys.CardMachineForm.ProcessMsg(CardMachineMessage)
0aa8f760 09bb5356 NSIISys.CardMachineForm.CardMachineMsgProcessor()
0aa8f7c0 792d6d66 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
0aa8f7cc 792e01ef System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
0aa8f7e4 792d6ce4 System.Threading.ThreadHelper.ThreadStart()
0aa8fa0c 79e71b4c [GCFrame: 0aa8fa0c] 
0:011> g
(1f0.e9c): Break instruction exception - code 80000003 (first chance)
eax=00000001 ebx=00000000 ecx=00000001 edx=0aa8e788 esi=00000000 edi=7a0979c6
eip=7c92120e esp=0aa8e2e8 ebp=0aa8e794 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200202
ntdll!DbgBreakPoint:
7c92120e cc              int     3
0:011> kbn
 # ChildEBP RetAddr  Args to Child              
00 0aa8e2e4 7a096467 0aa8e788 79f7762b 54504fde ntdll!DbgBreakPoint
01 0aa8e794 7a096796 80131506 7a0979c6 00000000 mscorwks!EEPolicy::LogFatalError+0x2b5
02 0aa8e7ac 7a0979d1 80131506 7a0979c6 00000000 mscorwks!EEPolicy::HandleFatalError+0x4d
03 0aa8e7d0 79f5f503 0aa8e850 5450404e 001bc838 mscorwks!CLRVectoredExceptionHandlerPhase3+0xbc
04 0aa8e804 79f5f3a5 0aa8e850 54504072 0aa8e990 mscorwks!CLRVectoredExceptionHandlerPhase2+0x20
05 0aa8e838 79edc2f8 0aa8e850 00004000 001bc838 mscorwks!CLRVectoredExceptionHandler+0x10a
06 0aa8e864 79edc4f5 0aa8e974 0aa8f81c 0aa8e948 mscorwks!CPFH_RealFirstPassHandler+0x607
07 0aa8e888 7c9232a8 0aa8e974 0aa8f81c 0aa8e990 mscorwks!COMPlusFrameHandler+0x15a
08 0aa8e8ac 7c92327a 0aa8e974 0aa8f81c 0aa8e990 ntdll!ExecuteHandler2+0x26
09 0aa8e95c 7c92e48a 00000000 0aa8e990 0aa8e974 ntdll!ExecuteHandler+0x24
0a 0aa8e95c 79f9423a 00000000 0aa8e990 0aa8e974 ntdll!KiUserExceptionDispatcher+0xe
0b 0aa8ed3c 79f92d5b 00000002 7a3b8ae0 00000001 mscorwks!WKS::gc_heap::plan_phase+0x5c3
0c 0aa8ed5c 79f932d5 00000000 7a3b8bc8 00080101 mscorwks!WKS::gc_heap::gc1+0x6e
0d 0aa8ed70 79f92fea 00000002 00000001 001bc838 mscorwks!WKS::gc_heap::garbage_collect+0x253
0e 0aa8ed9c 79f3d2a9 00000002 00000000 0aa8edcc mscorwks!WKS::GCHeap::GarbageCollectGeneration+0x1a9
0f 0aa8edac 79f3d2e5 00000002 00000000 001bc838 mscorwks!WKS::GCHeap::GarbageCollectTry+0x33
10 0aa8edcc 79f3d1a4 ffffffff 00000000 00000000 mscorwks!WKS::GCHeap::GarbageCollect+0x67
11 0aa8ee78 79777d16 09bb99aa 09bb98b8 00e95117 mscorwks!GCInterface::CollectGeneration+0xaa
12 0aa8efbc 79e96c8c 655f10e0 0aa8f028 0aa8f010 mscorlib_ni+0x6b7d16
13 0aa8efdc 79eb4afa 79eb4b13 01453830 01453830 mscorwks!MethodDescCallSite::Call_RetI4+0x1c
0:011> !clrstack
OS Thread Id: 0xe9c (11)
ESP       EIP     
0aa8ee28 7c92120e [HelperMethodFrame: 0aa8ee28] System.GC.nativeCollectGeneration(Int32, Int32)
0aa8ee80 79777d16 System.GC.Collect()
0aa8ee84 09bb99aa IFDMgr.ArtcCardGeniusI200Mgr.ExecCmd(System.String, Byte[] ByRef, Int32)
0aa8ef8c 09bb990f IFDMgr.ArtcCardGeniusI200Mgr.IFDMgr.IIFDMgr.ExecCmd(System.String, System.String ByRef, Int32)
0aa8efc0 0b00b4f7 NSIISys.CardMachineForm.InitDF(System.String, CPUCardKit.ICPUCardOperator, CoreControl.DFInfo)
0aa8f410 0b0087ad NSIISys.CardMachineForm.InitCard()
0aa8f5a4 09bb8d5b NSIISys.CardMachineForm.IssueCard()
0aa8f684 09bb8952 NSIISys.CardMachineForm.ProcessMsg(CardMachineMessage)
0aa8f760 09bb5356 NSIISys.CardMachineForm.CardMachineMsgProcessor()
0aa8f7c0 792d6d66 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
0aa8f7cc 792e01ef System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
0aa8f7e4 792d6ce4 System.Threading.ThreadHelper.ThreadStart()
0aa8fa0c 79e71b4c [GCFrame: 0aa8fa0c] 
0:011> g
eax=00000000 ebx=00000000 ecx=7c800000 edx=0aa8e418 esi=7c92de6e edi=80131506
eip=7c92e514 esp=0aa8e468 ebp=0aa8e564 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200246
ntdll!KiFastSystemCallRet:
7c92e514 c3              ret
0:011> kbn
 # ChildEBP RetAddr  Args to Child              
00 0aa8e464 7c92de7a 7c81cace ffffffff 80131506 ntdll!KiFastSystemCallRet
01 0aa8e468 7c81cace ffffffff 80131506 c0000005 ntdll!NtTerminateProcess+0xc
02 0aa8e564 7c81cb26 80131506 77e8f3b0 ffffffff KERNEL32!_ExitProcess+0x62
03 0aa8e578 79fdc444 80131506 001bc838 0aa8e990 KERNEL32!ExitProcess+0x14
04 0aa8e7a0 7a09679e 80131506 0aa8e7d0 7a0979d1 mscorwks!SafeExitProcess+0x157
05 0aa8e7ac 7a0979d1 80131506 7a0979c6 00000000 mscorwks!EEPolicy::HandleFatalError+0x55
06 0aa8e7d0 79f5f503 0aa8e850 5450404e 001bc838 mscorwks!CLRVectoredExceptionHandlerPhase3+0xbc
07 0aa8e804 79f5f3a5 0aa8e850 54504072 0aa8e990 mscorwks!CLRVectoredExceptionHandlerPhase2+0x20
08 0aa8e838 79edc2f8 0aa8e850 00004000 001bc838 mscorwks!CLRVectoredExceptionHandler+0x10a
09 0aa8e864 79edc4f5 0aa8e974 0aa8f81c 0aa8e948 mscorwks!CPFH_RealFirstPassHandler+0x607
0a 0aa8e888 7c9232a8 0aa8e974 0aa8f81c 0aa8e990 mscorwks!COMPlusFrameHandler+0x15a
0b 0aa8e8ac 7c92327a 0aa8e974 0aa8f81c 0aa8e990 ntdll!ExecuteHandler2+0x26
0c 0aa8e95c 7c92e48a 00000000 0aa8e990 0aa8e974 ntdll!ExecuteHandler+0x24
0d 0aa8e95c 79f9423a 00000000 0aa8e990 0aa8e974 ntdll!KiUserExceptionDispatcher+0xe
0e 0aa8ed3c 79f92d5b 00000002 7a3b8ae0 00000001 mscorwks!WKS::gc_heap::plan_phase+0x5c3
0f 0aa8ed5c 79f932d5 00000000 7a3b8bc8 00080101 mscorwks!WKS::gc_heap::gc1+0x6e
10 0aa8ed70 79f92fea 00000002 00000001 001bc838 mscorwks!WKS::gc_heap::garbage_collect+0x253
11 0aa8ed9c 79f3d2a9 00000002 00000000 0aa8edcc mscorwks!WKS::GCHeap::GarbageCollectGeneration+0x1a9
12 0aa8edac 79f3d2e5 00000002 00000000 001bc838 mscorwks!WKS::GCHeap::GarbageCollectTry+0x33
13 0aa8edcc 79f3d1a4 ffffffff 00000000 00000000 mscorwks!WKS::GCHeap::GarbageCollect+0x67
0:011> !clrstack
OS Thread Id: 0xe9c (11)
ESP       EIP     
0aa8ee28 7c92e514 [HelperMethodFrame: 0aa8ee28] System.GC.nativeCollectGeneration(Int32, Int32)
0aa8ee80 79777d16 System.GC.Collect()
0aa8ee84 09bb99aa IFDMgr.ArtcCardGeniusI200Mgr.ExecCmd(System.String, Byte[] ByRef, Int32)
0aa8ef8c 09bb990f IFDMgr.ArtcCardGeniusI200Mgr.IFDMgr.IIFDMgr.ExecCmd(System.String, System.String ByRef, Int32)
0aa8efc0 0b00b4f7 NSIISys.CardMachineForm.InitDF(System.String, CPUCardKit.ICPUCardOperator, CoreControl.DFInfo)
0aa8f410 0b0087ad NSIISys.CardMachineForm.InitCard()
0aa8f5a4 09bb8d5b NSIISys.CardMachineForm.IssueCard()
0aa8f684 09bb8952 NSIISys.CardMachineForm.ProcessMsg(CardMachineMessage)
0aa8f760 09bb5356 NSIISys.CardMachineForm.CardMachineMsgProcessor()
0aa8f7c0 792d6d66 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
0aa8f7cc 792e01ef System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
0aa8f7e4 792d6ce4 System.Threading.ThreadHelper.ThreadStart()
0aa8fa0c 79e71b4c [GCFrame: 0aa8fa0c] 
0:011> g
       ^ No runnable debuggees error in 'g'
A: 

Edit: Here's what's going on. You have an object instance of some type that contains unmanaged resources as members. That type has a finalizer (looks like a destructor syntax in C#) that calls Dispose(). Some part of your application relies on the unmanaged resource held by this object - perhaps a handle of type IntPtr. As long as the object stays alive (not collected by GC), Dispose() is never called an the handle remains valid. The problem is due to the program holding on to the raw handle (possibly an IntPtr) without keeping a reference to the managed object holding on to the resource. Without keeping that reference, the object becomes eligible for finalization/collection. Solution: Identify the managed type that manages your resource, and make sure you hold on to a copy of it until you no longer need its resource. When you no longer need the resource, call Dispose() on the managed object yourself to clean things up without needing to call GC.Collect().

280Z28
How is that supposed to cause a crash? Sure, it might make it slow, but it's not going to crash...
bdonlan
Also, the OP may have added it as debugging. If `GC.Collect()` causes a crash, _don't just remove it_ - you're just moving the crash somewhere else :)
bdonlan
Calling GC.Collect() can provoke a crash on another thread if that thread contains unmanaged code that references unpinned memory on the managed heap.
Bevan
My comment was mostly in response to something that made me go "oh dear..." However, I do know what causes this problem and I explained the source, reason calling `GC.Collect()` crashes, and the solution. :)
280Z28
+2  A: 

A crash (not exception) in GC means that unmanaged (ie, C++-CLR, unsafe, or non-.NET) code has corrupted the heap. Check your non-.NET code for potential issues! In particular, are those files in D:\jizg\NSIISys\bin\Debug .NET? If not, they look mighty suspicious to me.

bdonlan
A: 

There are a couple of messages that seem to be of interest:

WARNING: Unable to verify checksum for C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\6d667f19d687361886990f3ca0f49816\mscorlib.ni.dll

You may want to see why this error comes up, as it may be the problem with the unmanaged API.

Do you have any unmanaged C++ dlls that you wrote?

It seems to have a problem with an image name being possibly corrupt, so you may want to remove code that refers to images and see what happens, and then add in one section of code at a time until you find the block that causes a problem.

James Black
A: 

The defect is caused by stack corruption. Here is a technique that we use in my company to find these issues in release code.

First, download and run appverifier. This is a microsoft tool and only works on windows.

AppVerifier will force your unmanaged code to throw an exeption if there is any pointer problems. However, due to the way .NET initializes, .NET executables will also crash during startup with a false crash. What you need to do , is carefully write a test application in native C which will calls the same unmanaged functions as your .NET code.

Run your code in a debugger. The code will crash with the exact address of the pointer which is causing the problem.

Your code will run very slow. This is because AppVerifier will make windows load a series of tests on your test program.

Andrew Keith
A: 

Thanks for your kindly response,but I think the problem must be rooted in the usb 2 serial drivers,I'll paste my test result with hard serial port soon.thanks all again.

+1  A: 

Just don't do it. Find the problem and fix it rather than just quick-patching it. It will just move somewhere else.

erikkallen
The usb 2 serial port driver I used is provided by 3rd part.The chip model on usb calbe is FTDi.I also tried the driver of prolific 2303 and got the problem.So,the workable way to get rid of this problem is run my program on hard serial port ,if it works,I 'll give up the "soft serial port"-usb 2 serial port.Thank you!Jizhiguo