Original article address:Http://blogs.msdn.com/ B /tess/archive/2008/03/05/net-debugging-demos-lab-5-crash.aspx
Procedure:
1. Run companyinformation. aspx.
2. Enter a string in the input box, such as AAA. Click send.
3. After waiting for a few seconds, ie reports an error: the webpage cannot be displayed.
4. capture a crash dump and load SOS. Let's take a look! Threads, the output is as follows:
Hosted runtime: Yes
Preemptive GC alloc lock
Id osid threadobj state GC context domain count apt exception
XXXX 1 dd0 000dbce8 1808220 disabled quota :100000000 00102870 1 UKN (threadpool worker) system. stackoverflowexception (0291106c) (nested quota tions)
XXXX 2 f70 000e7ec8 b220 enabled restart :00000000 000d91a0 0 UKN (finalizer)
XXXX 3 f80 000ec3a8 1220 enabled restart :00000000 000d91a0 0 UKN
XXXX 4 868 000ff360 80a220 enabled restart :100000000 000d91a0 0 UKN (threadpool completion port)
XXXX 5 FAC 00151ad0 880a220 enabled restart :00000000 000d91a0 0 UKN (threadpool completion port)
There are five managed threads, but they are all suspended.
5. Re-capture dump and use the parameter-fullonfirst. After waiting for N long, dump is not finished. What's going on? Stop adplus and go to the dump directory to check whether there are 10 dump in two minutes, and the size is exactly the same.
6. Open the earliest dump. As it is a crash dump, windbg automatically switches to the problematic thread as follows:
OS thread ID: 0x364 (16)
ESP EIP
0203f1f0 7c80bee7 [helpermethodframe: 0203f1f0]
0203f294 05770ae7 buggymail. isvalidemailaddress (system. String)
Well, it seems that there is a problem with isvalidemailaddress.
7. Don't worry. Open the second dump and see:
OS thread ID: 0x364 (16)
ESP EIP
0203 efbc 7c80bee7 [helpermethodframe: 0203 efbc]
0203f060 7948d980 system. Io. _ error. winioerror (int32, system. String)
0203f08c 79395557 system. io. filestream. init (system. string, system. io. filemode, system. io. fileaccess, int32, Boolean, system. io. fileshare, int32, system. io. fileoptions, security_attributes, system. string, Boolean)
0203f184 793983c8 system. io. filestream .. ctor (system. string, system. io. filemode, system. io. fileaccess, system. io. fileshare, int32, system. io. fileoptions)
0203f1b0 793984e3 system. Io. streamwriter. createfile (system. String, Boolean)
0203f1c0 79398550 system. Io. streamwriter .. ctor (system. String, Boolean, system. Text. encoding, int32)
0203f1e0 7949959c system. Io. streamwriter... ctor (system. String)
0203f1ec 05770b52 utility. writetolog (system. String, system. String)
0203f220 05770b0b exceptionhandler. logexception (system. Exception)
0203f224 05770a81 buggymail. sendemail (system. String, system. String)
Interesting. In sendemail, logexception is called, And a winioerror is generated at the top.
8. Open the last one and see:
OS thread ID: 0x364 (16)
ESP EIP
0203ec4c 7c80bee7 [helpermethodframe: 0203ec4c]
0203ecf0 7948d980 system. Io. _ error. winioerror (int32, system. String)
0203ed1c 79395557 system. io. filestream. init (system. string, system. io. filemode, system. io. fileaccess, int32, Boolean, system. io. fileshare, int32, system. io. fileoptions, security_attributes, system. string, Boolean)
0203ee14 793983c8 system. io. filestream .. ctor (system. string, system. io. filemode, system. io. fileaccess, system. io. fileshare, int32, system. io. fileoptions)
0203ee40 793984e3 system. Io. streamwriter. createfile (system. String, Boolean)
0203ee50 79398550 system. Io. streamwriter .. ctor (system. String, Boolean, system. Text. encoding, int32)
0203ee70 7949959c system. Io. streamwriter .. ctor (system. String)
0203ee7c 05770b52 utility. writetolog (system. String, system. String)
0203eeb0 05770b0b exceptionhandler. logexception (system. Exception)
0203eeb4 05770bd4 utility. writetolog (system. String, system. String)
0203ef60 05770b0b exceptionhandler. logexception (system. Exception)
0203ef64 05770bd4 utility. writetolog (system. String, system. String)
0203f010 05770b0b exceptionhandler. logexception (system. Exception)
0203f014 05770bd4 utility. writetolog (system. String, system. String)
0203f0c0 05770b0b exceptionhandler. logexception (system. Exception)
0203f0c4 05770bd4 utility. writetolog (system. String, system. String)
0203f170 05770b0b exceptionhandler. logexception (system. Exception)
0203f174 05770bd4 utility. writetolog (system. String, system. String)
0203f220 05770b0b exceptionhandler. logexception (system. Exception)
0203f224 05770a81 buggymail. sendemail (system. String, system. String)
0203f2c8 05770a28 companyinformation. btncontact_click (system. Object, system. eventargs)
From the bottom of sendemail, logexception calls writetolog, then writetolog calls logexception, and the latter calls writetolog.
9. Combined with the last column of thread 1 in Step 4 above: stackoverflowexception, we guess the result of Step 8 above may be the cause of stackoverflowexception. So what does winioerror in the top row of Step 8 mean? Let's take a look at the variables on the stack on thread 16 that have a problem and run them! Result: (Part)
0203ee48 02b38358 system. String c: \ log.txt
0203ee54 02b3a850 system. String access to the path 'C: \ log.txt 'is denied.
10. I guess I want to access c: \ log.txt, but I don't have the permission to cause ioerror.
11. ViewCode, Find the sendemail section:
Public void sendemail (string message, string emailaddres ){
Try
{
If (isvalidemailaddress (emailaddres ))
{
// Send an email with the message
}
}
Catch (exception ex)
{
Exceptionhandler. logexception (Ex );
}
}
Back to step 6, an exception occurs from isvalidemailaddress. Because the string I entered is BBB, it is not a reasonable email address, so there will be an exception (you can refer to the isvalid method), and then the exception is thrown into the Catch Block.
12. Check how to write logexception in catch:
Public static void logexception (exception ex)
{
Utility. writetolog (ex. message, "C: \ log.txt ");
}
13. Ha, the above is shown! The c: \ log.txt string seen in DSO. This is okay. Let's see how to write writetolog. The Code is as follows:
Public static void writetolog (string message, string filename)
{
Try
{
Using (streamwriter Sw = new streamwriter (filename ))
{
// Log the event with date and time.
Sw. writeline ("--------------------------");
Sw. writeline (datetime. Now. tolongtimestring ());
Sw. writeline ("-------------------");
Sw. writeline (Message );
}
}
Catch (exception ex)
{
Exceptionhandler. logexception (Ex );
}
}
There may be problems in the try field, such as no permission or the file does not exist. The key point is that if an error occurs in a try, it will be thrown into the Catch Block and logexception will be executed.
Do you understand? If an exception occurs here, it is returned to step 12, and finally called here, and exception is returned to Step 12 ..................
14. Solution: manually create a c: \ log.txt file, right-click the file to modify the security, add the iuser_machine name user, and assign full control. Run againProgramOkay.
Over