Thursday, July 30, 2009

Finding CLR exceptions without visual studio

(If you want to understand what exception code 0xe0434352 is, read this post)

Often exceptions are thrown and caught and you don't see them. You probably know how to debug this in Visual Studio, so let me show you how to do it in cdb.
Sample Code:

class Program
 static void Main(string[] args)
     foreach (var x in Enumerable.Range(0,2000))
         Console.WriteLine("Hello World");


 private static void ThrowAndCatchException()
        throw new NotImplementedException();
Output of the application:
Hello World
Hello World
Hello World
Nothing about an exception, but you're sure it's happening behind the covers -- fire up cdb:
C:\Program Files\Debugging Tools for Windows (x64)>cdb -pn consoleapplication3.exe


ModLoad: 000007fe`f7e90000 000007fe`f7eb4000   C:\Windows\Microsoft.NET\Framework64\v4.0.20506\culture.dll
(ff8.17a8): Break instruction exception - code 80000003 (first chance)
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\SYSTEM32\ntdll.dll -
00000000`77b7d7b0 cc              int     3
Continue debugging:
0:004> g
Exceptions - lots of them:
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.16dc): CLR exception - code e0434352 (first chance)
(ff8.1860): Break instruction exception - code 80000003 (first chance)
Break on CLR exceptions:
0:004> sxe clr
0:004> g

(ff8.16dc): CLR exception - code e0434352 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\KERNELBASE.dll -
000007fe`fdb8bb5d 4881c4c8000000  add     rsp,0C8h
Load sos ( in .Net 2/3 use use !loadby sos mscorwks):
0:000> !loadby sos clr
View Stack:
0:000> !CLRStack
PDB symbol for clr.dll not loaded
OS Thread Id: 0x16dc (0)
Child SP         IP               Call Site
000000000096e6a8 000007fefdb8bb5d [HelperMethodFrame: 000000000096e6a8]
000000000096e7c0 000007ff00170360 ConsoleApplication3.Program.ThrowAndCatchException()
000000000096e810 000007ff001701fb ConsoleApplication3.Program.Main(System.String[])
000000000096ec90 000007feef474ca4 [GCFrame: 000000000096ec90]
View Exception:
0:000> !PrintException
Exception object: 0000000002c88c18
Exception type:   System.NotImplementedException
Message:          The method or operation is not implemented.
InnerException:   <none>
StackTrace (generated):
StackTraceString: <none>
HResult: 80004001
Pretty neat - eh?


Michael DePouw said...

Sweet, thanks!!!!

Rune said...

Thank you for this nice tips. It helped me solve a very frustrating problem when trying to deploy an C# app :)

And more importantly I'm now able to debug more effectively in the future.

sachin bhai said...

couldnt understand anything .... pls tell me how to solve this problem ....?

Udhaya kumar said...

while am shuting down the windows its showing me like

"The exception unknown software exception (0xe0434352)occurred in the application at location 0x850f89cc"

i doesnt know what to do now please help me...!!

Smart ignoramus said...

Same situation . Can't someone speak in lay men's terms speaking slowly and all steps needed.

njg123456 said...

Repeat of previous comment. How do I fix this "error". It affects Kaspersky Internet Security.

Yak said...

This totally just helped me solve my problem.

Thanks so much!

lee woo said...

The Constitution only gives people the right to pursue happiness. You have to catch it yourself. See the link below for more info.


sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.

Shea Kang said...

If you are not willing to learn, No one can help you. If you are determined to learn, No one can stop you.