Archive for the ‘.Net Framework’ Category

Full Call Stack of the current Call Sequence

Friday, August 8th, 2008

When debugging some problem, usually the “Call Stack” window is really of help. It let’s quickly see how you reached in current location i.e. call chain. This is of help when using some Visual Debugger, but you know what, the actual error happens when the application goes Live. For live applications, a good practice is to always log these errors in some database (or file) for latter analysis.

In .Net, during the runtime exception logging, most of us will use the Exception.StackTrace property to log the current stack trace. During analysis of different run-time errors, I found that some time the Exception.StrackTrace doesn’t return the full call chain. I think this is related to the classes which override the StackTrace property for content or format control.

Anyway, the good thing is that you can get full call chain, including the system calls, using the Environment.StackTrace. Though it’s large, but what it has is worth the bytes it consumes. Another advantage of the Environment.StackTrace property it works even when no exception has occurred.

Custom Date Format Parsing in .Net Framework

Monday, June 2nd, 2008

One has to often import and export dates in different format in the day to day programming. Though most of the .Net developers know how to export (convert the date to string) in a specific format, it’s little tricky when it comes to importing that i.e. loading the date in a custom string format to the .Net DateTime object.

Fortunately, in the .Net there is just a one line code for parsing and loading the date and time to DateTime object too. Here is C# sample on how to do this:

1
2
3
4
5
string strDateTime = "2004-02-12"; // You might load this from the database
DateTime dateTime;                 // This will hold the target parsed value
 
DateTime.TryParseExact(strDateTime, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, 
System.Globalization.DateTimeStyles.None, out item._listingEndDateTime);

I must admit that such utility functions really help to concentrate more on the actual problem. My kind regards to the developer of above method.