<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>David Szabo's [MSFT] blog : debugging</title><link>http://blogs.msdn.com/dszabo/archive/tags/debugging/default.aspx</link><description>Tags: debugging</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>MOM 2005 Response Script Tracing</title><link>http://blogs.msdn.com/dszabo/archive/2007/03/01/mom-2005-response-script-tracing.aspx</link><pubDate>Thu, 01 Mar 2007 13:22:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1778231</guid><dc:creator>dszabo</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dszabo/comments/1778231.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dszabo/commentrss.aspx?PostID=1778231</wfw:commentRss><description>&lt;p&gt;I've been writing a MOM response script that stopped working at some point, so I had to debug or trace it. Of course, at the time I was able to check it, the problem already got solved. So, I decided to turn on tracing and give some time for the problem to re-occur.&lt;/p&gt; &lt;p&gt;The script was developed to write trace messages at different points using the &lt;font face="Courier New"&gt;ScriptContext.Echo(string)&lt;/font&gt; method, but I never tried this feature. I did a search on MSDN and found that I have to enable debugging on the *MOM AGENT* (my script runs on a remote agent box, so I have to do it there) in order to get these messages logged somewhere. The following article shows the registry keys: &lt;a title="http://msdn2.microsoft.com/en-us/library/ms824564.aspx" href="http://msdn2.microsoft.com/en-us/library/ms824564.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms824564.aspx&lt;/a&gt;. Briefly, they are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;font face="Courier New"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Mission Critical Software\OnePoint\&lt;strong&gt;EnableActiveDebugging&lt;/strong&gt;&lt;/font&gt;&lt;strong&gt; &lt;/strong&gt;= 1&lt;/li&gt; &lt;li&gt;&lt;font face="Courier New"&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Mission Critical Software\OnePoint\&lt;strong&gt;DebugEnabledScripts&lt;/strong&gt;&lt;/font&gt; = &amp;lt;Your Response Script name&amp;gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Did that, restarted the MOM service on the agent box and found that a new log file created under &lt;em&gt;C:\WINDOWS\Temp\Microsoft Operations Manager &lt;/em&gt;with a name of "&lt;em&gt;AgentResponses-&amp;lt;Mgmt group name&amp;gt;&amp;nbsp;MOM.log&lt;/em&gt;", containing the last trace result of my response script.&lt;/p&gt; &lt;p&gt;So far so good, but I want to let my script-friend here doing his job and I want MOM to log every run, so I could analyze it next week when I come back. Unfortunately, MOM doesn't provide this nice feature to you, so I had to write my own scheduled task that does it:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;1. Created a batch script, called MomLogGatherer, with the following content (the current trace file is assigned to an existing file):&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font face="Courier New"&gt;type "C:\WINDOWS\Temp\Microsoft Operations Manager\AgentResponses-&amp;lt;Mgmt group name&amp;gt;&amp;nbsp;MOM.log" &amp;gt;&amp;gt; C:\dszabo_MS\MomLog\momlog.txt&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p&gt;2. Created a scheduled task to call the batch script in every 5 minutes (the response script in MOM is scheduled to run in every 5 mins)&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;I just have to take care to archive the file sometimes before it gets too big.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1778231" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dszabo/archive/tags/debugging/default.aspx">debugging</category><category domain="http://blogs.msdn.com/dszabo/archive/tags/MOM/default.aspx">MOM</category></item><item><title>How .net stores dates/how to debug them</title><link>http://blogs.msdn.com/dszabo/archive/2006/11/16/How-.net-stores-dates_2F00_how-to-debug-them.aspx</link><pubDate>Fri, 17 Nov 2006 01:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1089244</guid><dc:creator>dszabo</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/dszabo/comments/1089244.aspx</comments><wfw:commentRss>http://blogs.msdn.com/dszabo/commentrss.aspx?PostID=1089244</wfw:commentRss><description>&lt;P&gt;I was debugging an application and had to check a DateTime variable’s actual value. I was expecting something like member variables holding year, month, day, hour, etc values on the object and it will be an easy one to debug, but that was not the case, so I had to find out how to check the actual date value of a DateTime variable and learn how dates are stored in the .net framework 2.0.&lt;/P&gt;
&lt;P&gt;First of all, as you might already know, dumping out an object with SOS can be done with the !do (or !DumpObject) command. If you are not familiar with debugging .net, using WinDbg and using the SOS debugger extension, you can find a good starter at&amp;nbsp;&lt;A href="http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx&lt;/A&gt;, you can check the reference of the SOS extension at &lt;A href="http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/03/06/Bugslayer/default.aspx&lt;/A&gt;, then if you are still interested, you'll&amp;nbsp;find really good articles at Doug's (&lt;A href="http://blogs.msdn.com/dougste" mce_href="http://blogs.msdn.com/dougste"&gt;http://blogs.msdn.com/dougste&lt;/A&gt;) and Tess' (&lt;A href="http://blogs.msdn.com/tess" mce_href="http://blogs.msdn.com/tess"&gt;http://blogs.msdn.com/tess&lt;/A&gt;) blog. So, returning back to the subject, this is what you get when dumping out a DateTime variable:&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;0:000&amp;gt; !do 01481d74&lt;BR&gt;Name: System.DateTime&lt;BR&gt;MethodTable: 790ff4c4&lt;BR&gt;EEClass: 790ff424&lt;BR&gt;Size: 16(0x10) bytes&lt;BR&gt;&amp;nbsp;(E:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)&lt;BR&gt;Fields:&lt;BR&gt;Field&amp;nbsp;&amp;nbsp; Offset&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type VT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Attr&amp;nbsp;&amp;nbsp;&amp;nbsp; Value Name&lt;BR&gt;&lt;STRONG&gt;40000f4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.UInt64&amp;nbsp; 0 instance &lt;/STRONG&gt;&lt;STRONG&gt;630992916000000000 dateData&lt;BR&gt;&lt;/STRONG&gt;40000f0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32[]&amp;nbsp; 0&amp;nbsp;&amp;nbsp; shared&amp;nbsp;&amp;nbsp; static DaysToMonth365&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt; Domain:Value&amp;nbsp; 002401d8:01481cf4 &amp;lt;&amp;lt;&lt;BR&gt;40000f1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.Int32[]&amp;nbsp; 0&amp;nbsp;&amp;nbsp; shared&amp;nbsp;&amp;nbsp; static DaysToMonth366&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt; Domain:Value&amp;nbsp; 002401d8:01481d34 &amp;lt;&amp;lt;&lt;BR&gt;40000f2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.DateTime&amp;nbsp; 1&amp;nbsp;&amp;nbsp; shared&amp;nbsp;&amp;nbsp; static MinValue&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt; Domain:Value&amp;nbsp; 002401d8:01481cd4 &amp;lt;&amp;lt;&lt;BR&gt;40000f3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2c&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.DateTime&amp;nbsp; 1&amp;nbsp;&amp;nbsp; shared&amp;nbsp;&amp;nbsp; static MaxValue&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&amp;gt; Domain:Value&amp;nbsp; 002401d8:01481ce4 &amp;lt;&amp;lt;&lt;/P&gt;

&lt;/PRE&gt;
&lt;P&gt;The actual date value is&amp;nbsp;stored&amp;nbsp;in the UInt64 (long)&amp;nbsp;member variable called &lt;STRONG&gt;dateData&lt;/STRONG&gt;, which&amp;nbsp;stores the&amp;nbsp;ticks representing the date value. In my example, it is&amp;nbsp;630992916000000000. That's OK so far, but how can we get the date out from this? To convert it back without using your calculator or writing an expensive algorythm, you have to use the following DateTime constructor:&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;long&lt;/FONT&gt;&lt;FONT size=2&gt; ticks)&lt;/FONT&gt;&lt;/P&gt;&lt;/PRE&gt;
&lt;P&gt;or the following static method on the DateTime class:&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;public&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;static&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;DateTime&lt;/FONT&gt;&lt;FONT size=2&gt; FromBinary(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;long&lt;/FONT&gt;&lt;FONT size=2&gt; dateData)&lt;/FONT&gt;
&lt;/P&gt;&lt;/PRE&gt;
&lt;P&gt;Code that does the job:&lt;/P&gt;&lt;PRE&gt;&lt;P&gt;&lt;FONT color=#008080 size=2&gt;DateTime&lt;/FONT&gt;&lt;FONT size=2&gt; dateValue = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;DateTime&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;STRONG&gt;630992916000000000&lt;/STRONG&gt;);&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#008080 size=2&gt;Console&lt;/FONT&gt;&lt;FONT size=2&gt;.WriteLine(dateValue);&lt;/FONT&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1089244" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/dszabo/archive/tags/.net/default.aspx">.net</category><category domain="http://blogs.msdn.com/dszabo/archive/tags/debugging/default.aspx">debugging</category></item></channel></rss>