<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-19511232</id><updated>2011-11-06T03:31:55.971-08:00</updated><category term='tips exceptionhandling asp.net'/><title type='text'>Programming Life</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>38</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-19511232.post-3891994492682876561</id><published>2009-05-06T00:21:00.000-07:00</published><updated>2009-05-06T00:26:04.432-07:00</updated><title type='text'>blog has moved</title><content type='html'>I decided to move the blog to wordpress, as they have better support for displaying source-code.&lt;br /&gt;&lt;br /&gt;to do this I used en excellent utility at http://blogger2wordpress.appspot.com/&lt;br /&gt;&lt;br /&gt;If you were following me (I have no idea if anyone is) you might want to jump to http://andreascode.wordpress.com/&lt;br /&gt;&lt;br /&gt;this will be the last post on this blog-system.&lt;br /&gt;&lt;br /&gt;Cheers&lt;br /&gt;A&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-3891994492682876561?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/3891994492682876561/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=3891994492682876561' title='39 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3891994492682876561'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3891994492682876561'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2009/05/blog-has-moved.html' title='blog has moved'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>39</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-4244143397828880181</id><published>2009-04-29T05:16:00.000-07:00</published><updated>2009-04-29T05:19:26.538-07:00</updated><title type='text'>Extension methods</title><content type='html'>Imho: Extension methods should reside in the same namespace as the class they are extending (even if that namespace belongs to the .Net framework or a 3rd. party vendor.) This is the easiest way to keep functionality discoverable in a large solution.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-4244143397828880181?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/4244143397828880181/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=4244143397828880181' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4244143397828880181'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4244143397828880181'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2009/04/extension-methods.html' title='Extension methods'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-7054160796415918227</id><published>2009-04-28T23:04:00.000-07:00</published><updated>2009-04-28T23:23:48.833-07:00</updated><title type='text'>Shortcut your environment</title><content type='html'>The last few months I've spent a conscious effort to speed up my development. I have used resharper since version 1.5 (i think...) but have only recently found a lot of nifty stuff in it here's my favourites:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;ctrl + n = goto type  (classes)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;ctrl + shift + n = goto file (web.config / language files / aspx / ...)&lt;/li&gt;&lt;li&gt;Capitalized shortform (I write CMSG and r# suggests CustomerManagementServiceGateway (a class in our project) to me&lt;/li&gt;&lt;/ul&gt;These 3 alone amounts to 80% of my increased efficiency. I literally no longer search through the Solution explorer.&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_gWibonIMmIU/SffwOMK1gzI/AAAAAAAAFeE/7X4ww6X-ats/s1600-h/ScreenShot012.jpg"&gt;&lt;img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 162px; height: 200px;" src="http://3.bp.blogspot.com/_gWibonIMmIU/SffwOMK1gzI/AAAAAAAAFeE/7X4ww6X-ats/s200/ScreenShot012.jpg" alt="" id="BLOGGER_PHOTO_ID_5329992810591781682" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have also used True Launch Bar for my quick menu for a long time.&lt;br /&gt;having all programs I need categorized for easy access, but I started&lt;br /&gt;creating shortcuts for all the relevant folders on all the relevant machines, and that's sped me up quite a bit also. To see the folder where the web project is deployed in the build environment I hover the folder icon on the toolbar which pops up a list of environments, and drill my way in like that, all the icons are easily recognizable ( i set them myself) so to find any relevant place on any environment takes me &lt; .5 secs.&lt;br /&gt;&lt;br /&gt;Oh, did I mention I put a shortcut to the hosts-file in there also for each machine?&lt;br /&gt;&lt;br /&gt;I cannot recommend TrueLaunchBar.com enough. takes about an hour to set up the way I want it, but it's totally worth it&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-7054160796415918227?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/7054160796415918227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=7054160796415918227' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7054160796415918227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7054160796415918227'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2009/04/shortcut-your-environment.html' title='Shortcut your environment'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_gWibonIMmIU/SffwOMK1gzI/AAAAAAAAFeE/7X4ww6X-ats/s72-c/ScreenShot012.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-4237415839950826048</id><published>2009-04-27T05:03:00.000-07:00</published><updated>2009-04-27T05:37:42.332-07:00</updated><title type='text'>Tiny drips of Asp.Net juice</title><content type='html'>long time no see,&lt;br /&gt;&lt;br /&gt;I've been a busy little bee working on a fairly large web site for online gambling (horse races), with some SERIOUSLY cool software/frameworks. Going from the outside in it's been jQuery, EPiServer 5, Asp.Net 3.5, WCF, SOA, NHibernate. And I have learned more from this project than any other. I'm going to publish reference code (for my own later googling pleasure) from this project for quite a while I reckon. I'm starting easy with some webcontrols we have used throughout the solution. using our own has made it possible to enable/utilize jQuery very easily.&lt;br /&gt;&lt;br /&gt;to ensure the ID of controls are fixed, we have used this little trick:&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red190\green190\blue200;\red20\green20\blue20;\red205\green168\blue105;\red115\green134\blue165;}??\fs24 \cf1\cb2\highlight2  \cf3 public\cf1  \cf3 class\cf1  \cf4 ClientIdHiddenField\cf1 : \cf4 HiddenField\par ??\cf1     \{\par ??        \cf3 public\cf1  \cf3 override\cf1  \cf3 string\cf1  ClientID\par ??        \{\par ??            \cf3 get\par ??\cf1             \{\par ??                \cf3 return\cf1  ID;\par ??            \}\par ??        \}\par ??    \}} --&gt;&lt;br /&gt;&lt;div   style="background: rgb(20, 20, 20) none repeat scroll 0% 0%; color: rgb(190, 190, 200); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:12pt;"&gt;&lt;p style="margin: 0px;"&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(115, 134, 165);"&gt;ClientIdHiddenField&lt;/span&gt;: &lt;span style="color: rgb(115, 134, 165);"&gt;HiddenField&lt;/span&gt;&lt;/p&gt;{&lt;br /&gt;&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(205, 168, 105);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;string&lt;/span&gt; ClientID{&lt;span style="color: rgb(205, 168, 105);"&gt; get&lt;/span&gt;{ &lt;span style="color: rgb(205, 168, 105);"&gt;return&lt;/span&gt; ID; } }&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;This enables us to be certain that the jQuery selectors all work as expected&lt;br /&gt;&lt;br /&gt;similarly we have overridden labels/buttons/etc to enable us to give the webcontrols a TextKey property (e.g. TextKey="/app/game/gamewindow/buygame" ) declaratively, the TextKey is then used to lookup the correct text from the Translate function in EPiServer&lt;br /&gt;&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red190\green190\blue200;\red20\green20\blue20;\red205\green168\blue105;\red115\green134\blue165;\red143\green157\blue106;}??\fs24 \cf1\cb2\highlight2     \cf3 public\cf1  \cf3 class\cf1  \cf4 RikstotoButton\cf1 : \cf4 Button\par ??\cf1     \{\par ??        [\cf4 DefaultValue\cf1 (\cf5 ""\cf1 )]\par ??        \cf3 public\cf1  \cf3 string\cf1  TextKey\{ \cf3 get\cf1 ; \cf3 set\cf1 ; \}\par ??\par ??        \cf3 protected\cf1  \cf3 override\cf1  \cf3 void\cf1  OnPreRender(\cf4 EventArgs\cf1  e)\par ??        \{\par ??            \cf3 if\cf1  (\cf3 !string.\cf1 IsNullOrEmpty(TextKey) \cf3 &amp;amp;&amp;amp;\cf1  \cf3 string.\cf1 IsNullOrEmpty(Text))\par ??            \{\par ??                Text \cf3 =\cf1  \cf4 LanguageUtil\cf3 .\cf1 TranslateOrBlank(TextKey);\par ??            \}\par ??\par ??            \cf3 base.\cf1 OnPreRender(e);\par ??        \}\par ??    \}} --&gt;&lt;br /&gt;&lt;div   style="background: rgb(20, 20, 20) none repeat scroll 0% 0%; color: rgb(190, 190, 200); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:12pt;"&gt;    &lt;span style="color: rgb(205, 168, 105);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;class&lt;/span&gt; &lt;span style="color: rgb(115, 134, 165);"&gt;TranslateButton&lt;/span&gt;: &lt;span style="color: rgb(115, 134, 165);"&gt;Button&lt;/span&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;        [&lt;span style="color: rgb(115, 134, 165);"&gt;DefaultValue&lt;/span&gt;(&lt;span style="color: rgb(143, 157, 106);"&gt;""&lt;/span&gt;)]&lt;br /&gt;&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(205, 168, 105);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;string&lt;/span&gt; TextKey{ &lt;span style="color: rgb(205, 168, 105);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(205, 168, 105);"&gt;set&lt;/span&gt;; }&lt;/p&gt;        &lt;span style="color: rgb(205, 168, 105);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;void&lt;/span&gt; OnPreRender(&lt;span style="color: rgb(115, 134, 165);"&gt;EventArgs&lt;/span&gt; e)&lt;br /&gt;&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;            &lt;span style="color: rgb(205, 168, 105);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(205, 168, 105);"&gt;!string.&lt;/span&gt;IsNullOrEmpty(TextKey) &lt;span style="color: rgb(205, 168, 105);"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style="color: rgb(205, 168, 105);"&gt;string.&lt;/span&gt;IsNullOrEmpty(Text))&lt;br /&gt;&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;                Text &lt;span style="color: rgb(205, 168, 105);"&gt;=&lt;/span&gt; &lt;span style="color: rgb(115, 134, 165);"&gt;LanguageUtil&lt;/span&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;.&lt;/span&gt;TranslateOrBlank(TextKey);&lt;br /&gt;&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(205, 168, 105);"&gt;base.&lt;/span&gt;OnPreRender(e);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;As these are all just Custom Controls (no code-front file) we can specify their namespace in web.config:&lt;br /&gt;&lt;br /&gt;&lt;!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red215\green215\blue215;\red20\green20\blue20;\red205\green168\blue105;\red115\green134\blue165;\red143\green157\blue106;}??\fs24 \cf1\cb2\highlight2   &lt;\cf3 pages\cf1  \cf4 validateRequest\cf1 =\cf5 "false"\cf1  \cf4 enableEventValidation\cf1 =\cf5 "false"\cf1 &gt;\par ??      &lt;\cf3 controls\cf1 &gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "asp"\cf1  \cf4 namespace\cf1 =\cf5 "System.Web.UI"\cf1  \cf4 assembly\cf1 =\cf5 "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "asp"\cf1  \cf4 namespace\cf1 =\cf5 "System.Web.UI.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "EPiServer"\cf1  \cf4 namespace\cf1 =\cf5 "EPiServer.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "EPiServer"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "EPiServer"\cf1  \cf4 namespace\cf1 =\cf5 "EPiServer.Web.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "EPiServer"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "EPiServer"\cf1  \cf4 namespace\cf1 =\cf5 "EPiServer.Web.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "EPiServer.Web.WebControls"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "XForms"\cf1  \cf4 namespace\cf1 =\cf5 "EPiServer.XForms.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "EPiServer.XForms"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "WebParts"\cf1  \cf4 namespace\cf1 =\cf5 "EPiServer.WebParts.WebControls"\cf1  \cf4 assembly\cf1 =\cf5 "EPiServer"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "ajax"\cf1  \cf4 namespace\cf1 =\cf5 "AjaxControlToolkit"\cf1  \cf4 assembly\cf1 =\cf5 "AjaxControlToolkit"\cf1  /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 tagPrefix\cf1 =\cf5 "r22"\cf1  \cf4 namespace\cf1 =\cf5 "Rikstoto.Etoto.Web.CommonUC"\cf1  \cf4 assembly\cf1 =\cf5 "Rikstoto.Etoto.Web"\cf1  /&gt;\par ??\par ??      &lt;/\cf3 controls\cf1 &gt;\par ??    &lt;/\cf3 pages\cf1 &gt;} --&gt;&lt;br /&gt;&lt;div   style="background: rgb(20, 20, 20) none repeat scroll 0% 0%; color: rgb(190, 190, 200); -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;font-family:Consolas;font-size:12pt;"&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;pages&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; &lt;/span&gt;&lt;span style="color: rgb(115, 134, 165);"&gt;validateRequest&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(143, 157, 106);"&gt;"false"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; &lt;/span&gt;&lt;span style="color: rgb(115, 134, 165);"&gt;enableEventValidation&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(143, 157, 106);"&gt;"false"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;]&lt;/span&gt;&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;     [&lt;/span&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;controls]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;       ...........&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;                 [&lt;/span&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;add&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; &lt;/span&gt;&lt;span style="color: rgb(115, 134, 165);"&gt;tagPrefix&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(143, 157, 106);"&gt;"cc"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; &lt;/span&gt;&lt;span style="color: rgb(115, 134, 165);"&gt;namespace&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(143, 157, 106);"&gt;"OurNamespace.CommonUC"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; &lt;/span&gt;&lt;span style="color: rgb(115, 134, 165);"&gt;assembly&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(143, 157, 106);"&gt;"OurAssemblies.Web"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt; /]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt; &lt;/p&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;  [&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;controls&lt;/span&gt;]&lt;br /&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(215, 215, 215);"&gt;&lt;span style="color: rgb(205, 168, 105);"&gt;pages&lt;/span&gt;]&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;(couldn't get &lt; to work properly in markup here ...)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-4237415839950826048?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/4237415839950826048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=4237415839950826048' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4237415839950826048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4237415839950826048'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2009/04/tiny-drips-of-aspnet-juice.html' title='Tiny drips of Asp.Net juice'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-732009405104684051</id><published>2008-12-29T01:38:00.000-08:00</published><updated>2008-12-29T01:46:02.093-08:00</updated><title type='text'>VS2008 crash on "Choose items" in toolbox</title><content type='html'>So, today I was trying to include some MS Ajax control toolkit stuff on the web pages I'm building for a client. I right clicked on the toolbox, added a tab and clicked "Choose Items" then VS up and died on me. Lather rinse and repeat.&lt;br /&gt;&lt;br /&gt;Obviously something was very wrong here. After some googling I found a solution:&lt;br /&gt;- Start VS from VS command line in safe mode: &lt;strong&gt;&lt;span&gt;&lt;i&gt;devenv.exe /safemode&lt;/i&gt;&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;- Click "Choose items" again.&lt;br /&gt;- be sure to click all the tabs in the dialogue&lt;br /&gt;- observe an exception somewhere, and VS  will disable the faulty control&lt;br /&gt;- quit the safemode VS.&lt;br /&gt;- restart regular VS and try again&lt;br /&gt;&lt;br /&gt;.. VOILA!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-732009405104684051?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/732009405104684051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=732009405104684051' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/732009405104684051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/732009405104684051'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/12/vs2008-crash-on-choose-items-in-toolbox.html' title='VS2008 crash on &quot;Choose items&quot; in toolbox'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-7109934626166699168</id><published>2008-10-08T23:16:00.000-07:00</published><updated>2008-10-08T23:25:55.473-07:00</updated><title type='text'>string.Format returns the wrong kind of whitespace</title><content type='html'>ok, this one is weird:&lt;br/&gt;&lt;br /&gt;I write a custom util method to format money strings,&lt;br/&gt;&lt;br /&gt;it relies on string.Format("{0:n}", someValue).&lt;br/&gt;&lt;br /&gt;I cover it with unit tests to verify it works, and when I run them&lt;br/&gt;&lt;br /&gt;I get this little gem:&lt;br/&gt;&lt;br /&gt;&lt;img src="http://3.bp.blogspot.com/_gWibonIMmIU/SO2ioSGa74I/AAAAAAAAEpM/YthlqK9XFXU/s1600/2008-10-09_0812.png" /&gt;&lt;br/&gt;&lt;br /&gt;It turns out that the whitespace returned from string.Format is character 160, whereas the whitespace you normally get is character 32. &lt;br/&gt;&lt;br /&gt;So I change my method to replace all char 160 into char 32, and voila! all the tests pass...&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;what's up with that? I didn't even know there were two chars in .Net that both returned whitespace...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-7109934626166699168?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/7109934626166699168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=7109934626166699168' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7109934626166699168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7109934626166699168'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/10/stringformat-returns-wrong-kind-of.html' title='string.Format returns the wrong kind of whitespace'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_gWibonIMmIU/SO2ioSGa74I/AAAAAAAAEpM/YthlqK9XFXU/s72-c/2008-10-09_0812.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-7233775932453611805</id><published>2008-08-31T03:53:00.000-07:00</published><updated>2008-08-31T03:58:36.126-07:00</updated><title type='text'>changing the class item template in VS2008</title><content type='html'>It's been bugging me for too long, every bloody time I go new -&gt; class in VS2008,&lt;br /&gt;I get a class that is not set to public. I usually don't realize until I try to use the class at some later time.&lt;br /&gt;&lt;br /&gt;Today I finally snapped and fixed it.&lt;br /&gt;&lt;br /&gt;To change the template that is used to create new empty classes in VS2008,&lt;br /&gt;- Go to &lt;br /&gt;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033&lt;br /&gt;- unzip the class.zip.&lt;br /&gt;- change the class.cs file&lt;br /&gt;- zip it back up and replace the original .zip file.&lt;br /&gt;&lt;br /&gt;In yo face VS2008 default settings!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-7233775932453611805?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/7233775932453611805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=7233775932453611805' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7233775932453611805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/7233775932453611805'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/08/changing-class-item-template-in-vs2008.html' title='changing the class item template in VS2008'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-2625728700581985074</id><published>2008-08-28T14:45:00.000-07:00</published><updated>2008-08-29T00:17:51.829-07:00</updated><title type='text'>useful sorting of Lists</title><content type='html'>slightly in love with ruby/rails sorting&lt;br /&gt;some_list.sort_by{|person| person.age}&lt;br /&gt;&lt;br /&gt;I went ahead and made a sort function that only takes a Generic Func as input&lt;br /&gt;here goes:&lt;br /&gt;&lt;br /&gt;  public static class ListExtender&lt;br /&gt;  {&lt;br /&gt;          public static void Sort&amp;lt;T&amp;gt;(this List&amp;lt;T&amp;gt; list, Func&amp;lt;T, IComparable&amp;gt; func)&lt;br /&gt;          { &lt;br /&gt;                  list.Sort((a, b) =&amp;gt; func(a).CompareTo(func(b)));&lt;br /&gt;          }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;So I can now sort for instance cards like this:&lt;br /&gt;&lt;br /&gt;Cards.Sort(card =&gt; card.Value )&lt;br /&gt;&lt;br /&gt;Yay!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-2625728700581985074?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/2625728700581985074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=2625728700581985074' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/2625728700581985074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/2625728700581985074'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/08/useful-sorting-of-lists.html' title='useful sorting of Lists'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-8894112394693508390</id><published>2008-05-19T06:44:00.000-07:00</published><updated>2008-05-20T04:45:03.292-07:00</updated><title type='text'>Generic cache method</title><content type='html'>All of our code interacting with the cache is on the form&lt;br /&gt;&lt;br /&gt;string key = "persons"&lt;br /&gt;var cache = SimpleCache&lt;string,&gt;.Instance;&lt;br /&gt;if(cache.Exists(key) &amp;amp;&amp;amp; !HasExpired(Key)&lt;br /&gt;{&lt;br /&gt;return cache.Get(key);&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;int timeout_in_minutes = 5;&lt;br /&gt;var persons = PersonDAO.GetAllPersons();&lt;br /&gt;cache.Add(persons, timeout_in_minutes)&lt;br /&gt;return persons;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;&lt;br /&gt;So it's pretty tedious code to write, but relatively short and sweet. somewhat easy to introduce errors in the cache logic (which really should be the cache's responsibility after all)&lt;br /&gt;&lt;br /&gt;I decided I would try to write one that would be easier to consume, and here is code&lt;br /&gt;showing what I ended up with. The tests run as expected, I will leave it up to the reader&lt;br /&gt;(if I indeed have any) to figure out how CacheFetch gets stuff done, I found it to be pretty&lt;br /&gt;(yet a bit hard to grok) code that exemplifies the use of lambda-expressions and how a lambda&lt;br /&gt;can access variables that were present where it was defined, in addition to those present (in the form of input params) where it is executed&lt;br /&gt;&lt;br /&gt;--&lt;br /&gt;&lt;br /&gt;&lt;!--&lt;br /&gt;{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 using\cf0  System.Threading;\par ??\cf1 using\cf0  NUnit.Framework;\par ??\par ??\cf1 namespace\cf0  Business.Test\par ??\{\par ??    [\cf4 TestFixture\cf0 ]\par ??    \cf1 public\cf0  \cf1 class\cf0  \cf4 TestLambdas\par ??\cf0     \{\par ??        [\cf4 Test\cf0 ]\par ??        \cf1 public\cf0  \cf1 void\cf0  TestLamda()\par ??        \{\par ??            \cf1 var\cf0  serv = \cf1 new\cf0  \cf4 Serv\cf0 ();\par ??            \cf1 var\cf0  s1 = serv.GetCurrentMillis();\par ??            \cf4 Thread\cf0 .Sleep(20);\par ??            \cf1 var\cf0  s2 = serv.GetCurrentMillis();\par ??            \cf4 Assert\cf0 .AreEqual(s1, s2);\par ??        \}\par ??\par ??        [\cf4 Test\cf0 ]\par ??        \cf1 public\cf0  \cf1 void\cf0  TestLamda2()\par ??        \{\par ??            \cf1 var\cf0  serv = \cf1 new\cf0  \cf4 Serv\cf0 ();\par ??            \cf1 var\cf0  s1 = serv.GetRandomString(10);\par ??            \cf4 Thread\cf0 .Sleep(20);\par ??            \cf1 var\cf0  s2 = serv.GetRandomString(10);\par ??            \cf4 Assert\cf0 .AreEqual(s1, s2);\par ??            \cf4 Thread\cf0 .Sleep(20);\par ??            \cf1 var\cf0  s3 = serv.GetRandomString(10);\par ??            \cf4 Assert\cf0 .AreEqual(s2, s3);\par ??        \}\par ??    \}\par ??\par ??    \cf1 public\cf0   \cf1 class\cf0  \cf4 Serv\par ??\cf0     \{ \par ??        \cf1 public\cf0  \cf1 string\cf0  GetRandomString(\cf1 int\cf0  max_rand)\par ??        \{\par ??            \cf1 return\cf0  CacheFetch(\cf5 "rand"\cf0 , () =&amp;gt; \cf5 "rand"\cf0 +\cf1 new\cf0  \cf4 Random\cf0 ().Next(max_rand) ,5);\par ??        \}\par ??        \cf1 public\cf0  \cf1 int\cf0  GetCurrentMillis()\par ??        \{\par ??            \cf1 return\cf0  CacheFetch(\cf5 "day"\cf0 , () =&amp;gt; \cf4 DateTime\cf0 .Now.Millisecond, 5);\par ??        \}\par ??\par ??        \cf1 public\cf0  \cf1 delegate\cf0  T \cf4 Fetch\cf0 &amp;lt;T&amp;gt;();\par ??\par ??        \cf1 public\cf0  T CacheFetch&amp;lt;T, K&amp;gt;(K key, \cf4 Fetch\cf0 &amp;lt;T&amp;gt; fetcher, \cf1 int\cf0  cacheMinutes)\par ??        \{\par ??            \cf1 var\cf0  cache = \cf4 SimpleCache\cf0 &amp;lt;K, T&amp;gt;.Instance;\par ??            \cf1 if\cf0  (cache.Exists(key) &amp;amp;&amp;amp; !cache.HasExpired(key))\par ??            \{\par ??               \cf1 return\cf0  cache.GetItem(key);\par ??            \}\par ??            \cf1 var\cf0  retVal = fetcher();\par ??            cache.AddItem(key, retVal, cacheMinutes);\par ??            \cf1 return\cf0  retVal;\par ??        \}\par ??    \}\par ??\}}&lt;br /&gt;--&gt;&lt;br /&gt;&lt;div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; System.Threading;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;using&lt;/span&gt; NUnit.Framework;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;namespace&lt;/span&gt; Business.Test&lt;/p&gt;&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: #2b91af;"&gt;TestFixture&lt;/span&gt;]&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;TestLambdas&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: #2b91af;"&gt;Test&lt;/span&gt;]&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; TestLamda()&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; serv = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Serv&lt;/span&gt;();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; s1 = serv.GetCurrentMillis();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Thread&lt;/span&gt;.Sleep(20);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; s2 = serv.GetCurrentMillis();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Assert&lt;/span&gt;.AreEqual(s1, s2);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="color: #2b91af;"&gt;Test&lt;/span&gt;]&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; TestLamda2()&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; serv = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Serv&lt;/span&gt;();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; s1 = serv.GetRandomString(10);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Thread&lt;/span&gt;.Sleep(20);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; s2 = serv.GetRandomString(10);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Assert&lt;/span&gt;.AreEqual(s1, s2);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Thread&lt;/span&gt;.Sleep(20);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; s3 = serv.GetRandomString(10);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #2b91af;"&gt;Assert&lt;/span&gt;.AreEqual(s2, s3);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp; &lt;span style="color: blue;"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Serv&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; GetRandomString(&lt;span style="color: blue;"&gt;int&lt;/span&gt; max_rand)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; CacheFetch(&lt;span style="color: #a31515;"&gt;"rand"&lt;/span&gt;, () =&amp;gt; &lt;span style="color: #a31515;"&gt;"rand"&lt;/span&gt;+&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af;"&gt;Random&lt;/span&gt;().Next(max_rand) ,5);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; GetCurrentMillis()&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; CacheFetch(&lt;span style="color: #a31515;"&gt;"day"&lt;/span&gt;, () =&amp;gt; &lt;span style="color: #2b91af;"&gt;DateTime&lt;/span&gt;.Now.Millisecond, 5);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; &lt;span style="color: blue;"&gt;delegate&lt;/span&gt; T &lt;span style="color: #2b91af;"&gt;Fetch&lt;/span&gt;&amp;lt;T&amp;gt;();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;public&lt;/span&gt; T CacheFetch&amp;lt;T, K&amp;gt;(K key, &lt;span style="color: #2b91af;"&gt;Fetch&lt;/span&gt;&amp;lt;T&amp;gt; fetcher, &lt;span style="color: blue;"&gt;int&lt;/span&gt; cacheMinutes)&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; cache = &lt;span style="color: #2b91af;"&gt;SimpleCache&lt;/span&gt;&amp;lt;K, T&amp;gt;.Instance;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;if&lt;/span&gt; (cache.Exists(key) &amp;amp;&amp;amp; !cache.HasExpired(key))&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; cache.GetItem(key);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;var&lt;/span&gt; retVal = fetcher();&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cache.AddItem(key, retVal, cacheMinutes);&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: blue;"&gt;return&lt;/span&gt; retVal;&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-8894112394693508390?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/8894112394693508390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=8894112394693508390' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/8894112394693508390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/8894112394693508390'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/05/generic-cache-method.html' title='Generic cache method'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-5761762257415866761</id><published>2008-04-16T03:02:00.000-07:00</published><updated>2008-04-28T23:51:23.262-07:00</updated><title type='text'>Getting AnkhSVN to work with VS2008</title><content type='html'>For our project, we are using SVN as our code repository, integration with VS2008 can ba achieved by VisualSVN, but you have to pay for it. A free alternative is AnkhSVN, but after installing it, it works perfectly in VS2005, but won't show up in VS2008.&lt;br /&gt;&lt;br /&gt;The fix is to get the registry settings found in&lt;br /&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\AddIns\Ankh&lt;br /&gt;&lt;br /&gt;and put them into&lt;br /&gt;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\AddIns\Ankh&lt;br /&gt;&lt;br /&gt;here follows a snippet you can paste into a new .reg file and execute on your machine (assuming that you installed AnkhSVN in the default location "c:\program files\AnkhSVN"&lt;br /&gt;&lt;br /&gt;&lt;span&gt;*begin snippet*&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#3333ff;"&gt;&lt;span&gt;&lt;span&gt;Windows Registry Editor Version 5.00&lt;br /&gt;&lt;br /&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\AddIns]&lt;br /&gt;&lt;br /&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\AddIns\Ankh]&lt;br /&gt;"SatelliteDllPath"="C:\\Program Files\\AnkhSVN\\"&lt;br /&gt;"LoadBehavior"=dword:00000001&lt;br /&gt;"CommandPreload"=dword:00000001&lt;br /&gt;"AboutBoxIcon"=""&lt;br /&gt;"CommandLineSafe"=dword:00000000&lt;br /&gt;"Description"="Subversion addin for Visual Studio .NET 2008"&lt;br /&gt;"FriendlyName"="AnkhSVN"&lt;br /&gt;"SatelliteDllName"="BitmapDll.dll"&lt;br /&gt;"AboutBoxDetails"="Please visit http://ankhsvn.tigris.org for more information&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Below is the version information for the various AnkhSVN components&lt;br /&gt;&lt;br /&gt;AnkhSVN 1.0.2.2778&lt;br /&gt;&lt;br /&gt;OpenSSL 0.9.8a&lt;br /&gt;&lt;br /&gt;Neon 0.25.5&lt;br /&gt;&lt;br /&gt;ZLib 1.2.3&lt;br /&gt;&lt;br /&gt;Berkeley DB 4.4.20&lt;br /&gt;&lt;br /&gt;Subversion 1.4.5&lt;br /&gt;&lt;br /&gt;Ankh 1.0.2Final&lt;br /&gt;&lt;br /&gt;apr-iconv 0.9.7&lt;br /&gt;&lt;br /&gt;apr-util 0.9.12&lt;br /&gt;&lt;br /&gt;apr 0.9.12"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;br /&gt;*end snippet*&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-5761762257415866761?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/5761762257415866761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=5761762257415866761' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/5761762257415866761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/5761762257415866761'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2008/04/getting-ankhsvn-to-work-with-vs2008.html' title='Getting AnkhSVN to work with VS2008'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-4899634599121087423</id><published>2008-03-30T23:33:00.000-07:00</published><updated>2009-01-07T04:48:54.551-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tips exceptionhandling asp.net'/><title type='text'>General exception handling in web parts</title><content type='html'>Some time ago, I wrote a general transparent exception handling module for use in a MOSS 2007 (Sharepoint) solution. The solution had many web parts, web parts that would often break, causing the entire page they were on to crash. This was causing our testers no end of misery, as they couldn't easily see which part of the page was responsible for the crash, nor could they continue their testing until the web part had been fixed. Often, the crashing web part wasn't even relevant for the testers, but it still kept them from doing their work. Clearly something needed to be done.&lt;br /&gt;&lt;br /&gt;You might argue that the best solution would be to buckle up and just fix the dang web parts.. but there were a lot of them, and the coders responsible for the mess had moved on (sounds familiar?) so we had the idea to use a general all-purpose exception handling strategy for the parts.&lt;br /&gt;&lt;br /&gt;We wanted a crash in a web part or web control etc. not to crash the entire page, but instead to output the stacktrace inline in the web page during development, and to have a friendly message (defined by the webparts themselves, or a standard message) outputted to the user in run time, in stead of bringing the entire page down.&lt;br /&gt;&lt;br /&gt;At the time we didn't know of any such solution. (I still don't).&lt;br /&gt;The best, I  think, would be if something like what I made (the file is included) was included into the ASP.Net framework. (if any of you ASP.Net guys are reading this: feel free to take my code and  adapt it. It     works better the higher it is in the class hierarchy&lt;br /&gt;It could for instance be a part of System.Web.UI.WebControls.WebControl, with some web.config setting you could tweak to activate it... it would help heaps during development.. at least it would help me :) )&lt;br /&gt;&lt;br /&gt;so, on to the solution we ended with:&lt;br /&gt;I made a BaseWebPart which all the other web parts (the ones that were crashing intermittently) would inherit from. When inherited from, the BaseWebPart would ensure that a try/catch surrounded all the calls coming from the ASP.Net framework (Render, CreateChildControls .. etc.) so that a crash happening in one of these was handled nicely.&lt;br /&gt;Each web part could then override a method called HandleException to control what happened if it crashed. the default behaviour (if they didn't override) was set to be&lt;br /&gt;&lt;br /&gt;render the stacktrace when in debug mode&lt;br /&gt;or&lt;br /&gt;render a standard error message when in release mode&lt;br /&gt;&lt;br /&gt;In order to wrap each framework call with exception handling,&lt;br /&gt;we had a two-tiered approach in which&lt;br /&gt;1) the first tier (ExceptionHandlingWebPartBase) overrides and seals methods,&lt;br /&gt;2) then applies try/catch to a new set of methods, forwarding method parameters&lt;br /&gt;3) these new methods are overridden in the second tier (BaseWebPart)&lt;br /&gt;4) where they are sealed and a call is made to new virtual methods that are named the same as the framework methods.&lt;br /&gt;5) These methods (now with a catch-block around them) are then overridden as needed in a regular web part that inherits from BaseWebPart. The exception handling is thus transparent to the inheritor.&lt;br /&gt;&lt;br /&gt;The only downside of this module was that MOSS has several "base" web parts you would inherit from to make your own web parts, so this BaseWebPart had to be duplicated once for each of these. &lt;br /&gt;We also wanted this functionality on web controls, &lt;br /&gt;so we had to basically duplicate the code to make a BaseWebControl also.&lt;br /&gt;If this error handling module was included higher in the hierarchy, for instance in WebControl or Control, once would be enough to cover all the different cases. Unfortunately c# doesn't allow mixins, or we would probably be able to get away with applying the exception handling all over in one fell swoop. As it stands, 4-5 classes of duplicated, identical code was found to be preferrable to 40-50 classes with duplicated exception handling logic.&lt;br /&gt;&lt;br /&gt;"did it work?" you ask? well the benefits derived from this setup included&lt;br /&gt;1) no need to emergency hotfix testing environments during testing&lt;br /&gt;2) guaranteed logging of exceptions in production&lt;br /&gt;3) a generally more sober error classification from the testers (before they would just say "everyting is down, this page doesn't work - this is unacceptable, level 1 error"&lt;br /&gt;4) some exceptions in the web parts snuck into production, but instead of causing the entire page to halt, a friendly message was shown, buying us a great deal of time in fixing the problem ( next release instead of hotfix)&lt;br /&gt;&lt;br /&gt;I'm definately using this setup again the next time I'm in a project with lots of web parts, web controls or custom controls.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is the code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.IO;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI;&lt;br /&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;&lt;br /&gt;&lt;br /&gt;&lt;span class="rem"&gt;///*'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// This is the work of Andreas Knudsen (andreas.knudsen [ at ] gmail.com)&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Anyone may use this work freely as it stands, or change it to suit their needs&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// on one condition: All use is on your own risk. It works for me, but I will not be&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// liable for any losses incurred by the use of this work. &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// If you would hold me responsible, you are not to use this work.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// ************************************************************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// In order to be truly useful, customizations are needed on lines 120 and 130&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// ************************************************************************************&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Util&lt;br /&gt;{&lt;br /&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Base class for web part development. &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// All web parts should inherit from this class. &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// Exceptions thrown from web parts inheriting from this base &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// will not crash the Page the web part is on, but rather do one of two things:&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 1)If compiled in debug mode: Render the stacktrace of the exception inline in the web page&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 2)If compiled in release mode: Render a friendly error message inline in the web page.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// This behaviour can be overridden by inheritors by overriding the method HandleException&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;///  &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// HOW THIS WORKS:&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// -------&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// In order to wrap each framework call with exception handling, &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// we have a two-tiered approach in which &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 1) the first tier (ExceptionHandlingWebPartBase) overrides and seals methods, &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 2) then applies try/catch to a new set of methods, forwarding method parameters&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 3) these new methods are overridden in the second tier (BaseWebPart)&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 4) where they are sealed and a call is made to new virtual methods that are named the &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// same as the framework methods.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// 5) These methods (now with a catch-block around them) are then overridden as needed in a &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// regular web part that inherits from BaseWebPart. The exception handling is thus &lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// transparent to the inheritor.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BaseWebPart : ExceptionHandlingWebPartBase&lt;br /&gt;{&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; temp methods &lt;span class="kwrd"&gt;for&lt;/span&gt; method piping (overrides and seals methods from ExceptionHandlingWebPartBase)&lt;br /&gt;  &lt;span class="rem"&gt;/*&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;         * These methods re part of the plumbing necessary to give inheritors&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;         * the expected interface.&lt;/span&gt;&lt;br /&gt;&lt;span class="rem"&gt;         */&lt;/span&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RenderWebPart(HtmlTextWriter writer)&lt;br /&gt;  {&lt;br /&gt;      Render(writer);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateWebPartChildControls()&lt;br /&gt;  {&lt;br /&gt;      CreateChildControls();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      OnInit(e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PreRenderWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      OnPreRender(e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LoadWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      OnLoad(e);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; Methods &lt;span class="kwrd"&gt;in&lt;/span&gt; which exceptions are now handled.&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Render(HtmlTextWriter writer)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.RenderWebPart(writer);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateWebPartChildControls();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnInit(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.InitWebPart(e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoad(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.LoadWebPart(e);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPreRender(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.PreRenderWebPart(e);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;abstract&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ExceptionHandlingWebPartBase : WebPart&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; Exception handling section&lt;br /&gt;  &lt;span class="kwrd"&gt;private&lt;/span&gt; StringBuilder _errorOutput;&lt;br /&gt;  &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; _abortProcessing;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; AbortProcessing&lt;br /&gt;  {&lt;br /&gt;      get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _abortProcessing; }&lt;br /&gt;      set { _abortProcessing = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; HandleException(Exception e, HtmlTextWriter writer)&lt;br /&gt;  {&lt;br /&gt;&lt;span class="preproc"&gt;#if&lt;/span&gt; !DEBUG&lt;br /&gt;      writer.Write(&lt;span class="str"&gt;"TODO: Insert helpful error message here"&lt;/span&gt;);&lt;br /&gt;&lt;span class="preproc"&gt;#else&lt;/span&gt;&lt;br /&gt;      writer.Write(e.Message + &lt;span class="str"&gt;"&amp;lt;br/&amp;gt;"&lt;/span&gt; + e.StackTrace);&lt;br /&gt;&lt;span class="preproc"&gt;#endif&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExceptionHappened(Exception ex)&lt;br /&gt;  {&lt;br /&gt;      AbortProcessing = &lt;span class="kwrd"&gt;true&lt;/span&gt;;&lt;br /&gt;      &lt;span class="rem"&gt;//TODO: use own logging framework here:&lt;/span&gt;&lt;br /&gt;      &lt;span class="rem"&gt;//Logger.Log(Severity.Error, ex.Message + " " + ex.StackTrace);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;      HandleException(ex, &lt;span class="kwrd"&gt;new&lt;/span&gt; HtmlTextWriter(&lt;span class="kwrd"&gt;new&lt;/span&gt; StringWriter(_errorOutput)));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; Override framework methods &lt;span class="kwrd"&gt;for&lt;/span&gt; method piping&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()&lt;br /&gt;  {&lt;br /&gt;&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!AbortProcessing)&lt;br /&gt;      {&lt;br /&gt;          &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;          {&lt;br /&gt;              CreateWebPartChildControls();&lt;br /&gt;          }&lt;br /&gt;          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)&lt;br /&gt;          {&lt;br /&gt;              ExceptionHappened(e);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnInit(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      AbortProcessing = &lt;span class="kwrd"&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;      _errorOutput = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;&lt;br /&gt;      &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;      {&lt;br /&gt;          InitWebPart(e);&lt;br /&gt;      }&lt;br /&gt;      &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;      {&lt;br /&gt;          ExceptionHappened(ex);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Render(HtmlTextWriter writer)&lt;br /&gt;  {&lt;br /&gt;      StringBuilder tempOutput = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!AbortProcessing)&lt;br /&gt;      {&lt;br /&gt;          HtmlTextWriter tempWriter = &lt;span class="kwrd"&gt;new&lt;/span&gt; HtmlTextWriter(&lt;span class="kwrd"&gt;new&lt;/span&gt; StringWriter(tempOutput));&lt;br /&gt;&lt;br /&gt;          &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;          {&lt;br /&gt;              RenderWebPart(tempWriter);&lt;br /&gt;          }&lt;br /&gt;          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;          {&lt;br /&gt;              ExceptionHappened(ex);&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (AbortProcessing)&lt;br /&gt;      {&lt;br /&gt;          writer.Write(_errorOutput.ToString());&lt;br /&gt;      }&lt;br /&gt;      &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;      {&lt;br /&gt;          writer.Write(tempOutput.ToString());&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnLoad(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!AbortProcessing)&lt;br /&gt;      {&lt;br /&gt;          &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;          {&lt;br /&gt;              LoadWebPart(e);&lt;br /&gt;          }&lt;br /&gt;          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;          {&lt;br /&gt;              ExceptionHappened(ex);&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; OnPreRender(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;if&lt;/span&gt; (!AbortProcessing)&lt;br /&gt;      {&lt;br /&gt;   &lt;br /&gt;          &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;br /&gt;          {&lt;br /&gt;              PreRenderWebPart(e);&lt;br /&gt;          }&lt;br /&gt;          &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)&lt;br /&gt;          {&lt;br /&gt;              ExceptionHappened(ex);&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class="preproc"&gt;#region&lt;/span&gt; Temp methods &lt;span class="kwrd"&gt;for&lt;/span&gt; method piping (will be overridden and &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; subclass)&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RenderWebPart(HtmlTextWriter writer)&lt;br /&gt;  {&lt;br /&gt;      EnsureChildControls();&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.Render(writer);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateWebPartChildControls()&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InitWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnInit(e);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LoadWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnLoad(e);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;virtual&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; PreRenderWebPart(EventArgs e)&lt;br /&gt;  {&lt;br /&gt;      &lt;span class="kwrd"&gt;base&lt;/span&gt;.OnPreRender(e);&lt;br /&gt;  }&lt;br /&gt;  &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-4899634599121087423?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/4899634599121087423/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=4899634599121087423' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4899634599121087423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/4899634599121087423'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2007/12/general-exception-handling-in-web-parts.html' title='General exception handling in web parts'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-3429322668316231925</id><published>2007-12-06T00:23:00.001-08:00</published><updated>2007-12-06T00:23:59.319-08:00</updated><title type='text'>Test from IMified</title><content type='html'>&lt;br /&gt;    &lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;br /&gt;      Found this sweet MSN-thingy that lets me write the blog entries as a conversation to a contact in MSN, &lt;br /&gt;the contact said "enter a title" and "enter the content",  (which is what I'm currently typing)..... I wonder how this will come out on the other end...&lt;br /&gt;    &lt;/div&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-3429322668316231925?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/3429322668316231925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=3429322668316231925' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3429322668316231925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3429322668316231925'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2007/12/test-from-imified.html' title='Test from IMified'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-6644142840999131032</id><published>2007-08-02T10:28:00.000-07:00</published><updated>2007-08-02T10:32:33.399-07:00</updated><title type='text'>Visual Studio debugger trick</title><content type='html'>In order to show a custom string when viewing a custom object in the visual studio debugger,&lt;br /&gt;&lt;br /&gt;you can attribute the class with&lt;br /&gt;[[DebuggerDisplay("sometext")]]&lt;br /&gt;if sometext includes "{parametername}" the value of the parameter with the given name (parametername in this case) will be shown at that point.&lt;br /&gt;&lt;br /&gt;If you need more control than that, you can always build a custom debugger visualizer (google it)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-6644142840999131032?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/6644142840999131032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=6644142840999131032' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/6644142840999131032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/6644142840999131032'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2007/08/visual-studio-debugger-trick.html' title='Visual Studio debugger trick'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-3271600552392319902</id><published>2007-03-08T01:17:00.000-08:00</published><updated>2007-03-08T01:24:20.485-08:00</updated><title type='text'>Cannot Open the File: Mk:@MSITStore:C:\....</title><content type='html'>I was recently plagued by this message whenever  wanted to read .chm files. And since the only useful documentation published by the  vendors of the CMS  I'm currently developing for is in .CHM files, it was getting to me quick.&lt;br/&gt;&lt;br/&gt;Luckily Google prevailed yet again and gave me this result on my query:&lt;br/&gt;&lt;a href="http://techrepublic.com.com/5208-11183-0.html?forumID=89&amp;threadID=191474"&gt;http://techrepublic.com.com/5208-11183-0.html?forumID=89&amp;amp;threadID=191474&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;in which my solution  was found:&lt;br/&gt;&lt;snip&gt;&lt;br/&gt;Open a CMD window, type the following on the command line:&lt;br/&gt;&lt;br/&gt;regsvr32 %systemroot%\system32\hhctrl.ocx &lt;press&gt;&lt;br/&gt;regsvr32 %systemroot%\system32\itss.dll &lt;press&gt;&lt;br/&gt;&lt;br/&gt;You will receive a success message after each of these commands.&lt;br/&gt;&lt;/snip&gt;&lt;br/&gt;&lt;br/&gt;thank you "Perk" from Mölnlycke, SE, for making my day!&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-3271600552392319902?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/3271600552392319902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=3271600552392319902' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3271600552392319902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/3271600552392319902'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2007/03/cannot-open-file-mkmsitstorec.html' title='Cannot Open the File: Mk:@MSITStore:C:\....'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-116660906108098584</id><published>2006-12-20T01:57:00.000-08:00</published><updated>2006-12-20T02:04:21.093-08:00</updated><title type='text'>ASP.NET 2.0 mystical Ambigous match</title><content type='html'>I recently upgraded a website from asp.net 1.1 to asp.net 2.0 "web application project"&lt;br /&gt;&lt;br /&gt;Everything worked fine except for one small page that just wouldn't run, The first line of the aspx file reported an "ambigous match" error, and when I ran the page the same error cropped up.&lt;br /&gt;&lt;br /&gt;It turns out that the culprit was a textbox that was defined two times in the codebehind:&lt;br /&gt;&lt;br /&gt;protected TextBox txtPostNumber&lt;br /&gt;protected TextBox txtPostnumber&lt;br /&gt;&lt;br /&gt;with the only difference being in the casing.&lt;br /&gt;Althought this clearly is fishy code, the second textbox was never used, so no harm done right?&lt;br /&gt;well ASP.NET 1.1 handles this like you would expect, ignoring the other textbox. &lt;br /&gt;ASP.NET 2.0 on the other hand gave me the before mentioned cryptic "ambigous match" error. It turns out that ASP.NET 2.0 acts case-insensitively in this regard.&lt;br /&gt;&lt;br /&gt;I wonder why they changed it, and why they can't give a more useful error message...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-116660906108098584?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/116660906108098584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=116660906108098584' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/116660906108098584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/116660906108098584'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/12/aspnet-20-mystical-ambigous-match.html' title='ASP.NET 2.0 mystical Ambigous match'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-115588493162188901</id><published>2006-08-18T00:02:00.000-07:00</published><updated>2006-08-18T00:10:08.536-07:00</updated><title type='text'>Textbox submit on enter</title><content type='html'>In .net 1.1, getting a textbox to submit on enter pressed is easy, &lt;br /&gt;&lt;br /&gt;Put in the textbox (we'll call it UserPassword here) on the form (runat="server") and declare it in the codebehind with the same ID)&lt;br /&gt;&lt;br /&gt;Have a submit button, either of type &amp;lt;asp:Button id="BtnSubmit" runat="server"../&amp;gt; or &amp;lt;input id="BtnSubmit" runat="server"...&amp;gt; on the form,&lt;br /&gt;declare a variable in the codebehind with the same ID as the button or input and of the same type (Button or HtmlInputButton)&lt;br /&gt;&lt;br /&gt;Wire the submit button up to do the actual submitting and then in Page_Init or Page_Load write this line of code (13 is the magical number for the enter key)&lt;br /&gt;&lt;br /&gt;UserPassword.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+BtnSubmit.UniqueID+"').click();return false;}} else {return true}; ");&lt;br /&gt;&lt;br /&gt;and there you have it&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-115588493162188901?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/115588493162188901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=115588493162188901' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/115588493162188901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/115588493162188901'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/08/textbox-submit-on-enter.html' title='Textbox submit on enter'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-115098211784855124</id><published>2006-06-22T06:13:00.000-07:00</published><updated>2006-06-22T06:16:31.723-07:00</updated><title type='text'>String to Enum C#</title><content type='html'>I found this little snippet on a blog by Mark Wagner's blog, &lt;br /&gt;and already this baby has saved me quite a bit of work, so I thought I'd post it also, btw. Marks blog can be found  &lt;a href="http://blogs.crsw.com/mark/"&gt; here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Convert a string to an enumerated (enum) value.&lt;br /&gt;&lt;br /&gt;Using the Enum.Parse method, you can easily convert a string value to an enumerated value.  Doing this requires the type of the enum and string value.  Adding the true argument will cause the case to be ignored.&lt;br /&gt;&lt;br /&gt;Using the following enum for this example:&lt;br /&gt;&lt;br /&gt;private enum Aircraft&lt;br /&gt;{&lt;br /&gt;   Beech,&lt;br /&gt;   Cessna,&lt;br /&gt;   Piper&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;You can easily convert the string to an enum value like this:&lt;br /&gt;&lt;br /&gt;Aircraft air = (Aircraft) Enum.Parse(typeof(Aircraft), "Cessna", true); &lt;br /&gt;&lt;br /&gt;Ideally you should wrap a try-catch around the Enum.Parse statement.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-115098211784855124?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/115098211784855124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=115098211784855124' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/115098211784855124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/115098211784855124'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/06/string-to-enum-c.html' title='String to Enum C#'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114872653421611402</id><published>2006-05-27T03:29:00.000-07:00</published><updated>2006-05-27T03:42:14.226-07:00</updated><title type='text'>watching for changes in webapps</title><content type='html'>Recently I came across code in a project that had been built to check for changes in order to give the user warnings like "remember to save.." "do you really want to navigate away.." etc. As this project uses Typed datasets for all they're worth (which is quite a lot as long as the complexity of the domain is easily managed) the actual check for changes was done through calling the datasets ToXml() method and holding that string in the session and constantly check against that as the user went about his business. &lt;br /&gt;&lt;br /&gt;Now, this project had in NO way a stateless web server, but then the requirements didn't call for that either, but still. each dataset (of which the user would typically have 1-20 of within a session) was saved in the session and also its xml was saved (to perform change-watching).&lt;br /&gt;&lt;br /&gt;Thw problem was that although there were few users (&amp;lt;10), the xml for each dataset had a footprint of about 1.6 MB each. &lt;br /&gt;&lt;br /&gt;So what did I do to ease the pain? I changed the code to check and save not the raw xml, but a hash of the xml. To do this I made one small method that translated from string to a hashed string, All up I spent about 20 minutes implementing and testing this schema and the estimated footprint-savings is in the area of 150 MB of server memory.&lt;br /&gt;&lt;br /&gt;so what about the code eh? well here it is:&lt;br /&gt;&lt;br /&gt;public static string ComputeHashFromString(string message, HashAlgorithm ha)&lt;br /&gt;  {&lt;br /&gt;   byte[] msgbytes = ASCIIEncoding.ASCII.GetBytes(message);&lt;br /&gt;   byte[] hashBytes = ha.ComputeHash(msgbytes);&lt;br /&gt;   StringBuilder sb = new StringBuilder();&lt;br /&gt;   foreach(byte b in hashBytes)&lt;br /&gt;   {&lt;br /&gt;    sb.Append(b.ToString("x2"));&lt;br /&gt;   }&lt;br /&gt;   return sb.ToString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static string ComputeHashFromString(string message)&lt;br /&gt;  {&lt;br /&gt;   return ComputeHashFromString(message, new MD5CryptoServiceProvider());&lt;br /&gt;  }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114872653421611402?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114872653421611402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114872653421611402' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114872653421611402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114872653421611402'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/05/watching-for-changes-in-webapps.html' title='watching for changes in webapps'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114776528318882521</id><published>2006-05-16T00:30:00.000-07:00</published><updated>2006-05-16T00:41:23.200-07:00</updated><title type='text'>Making Custom Properties aware of their context in EPiServer</title><content type='html'>What you might want to do inside a custom property is to check the value of some other properties in the current page. What you will notice is that Custom Properties are not aware of the CurrentPage, in order to fetch it you will need to override the &lt;br /&gt;InitializeData method that the base class of all EPiServer properties has.&lt;br /&gt;&lt;br /&gt;You can get the pagereference within that method &lt;br /&gt;&lt;br /&gt;PageReference _pageLink;&lt;br /&gt;&lt;br /&gt;public override void InitializeData(EPiServer.ApplicationConfiguration config,PropertyDataCollection properties)&lt;br /&gt;{&lt;br /&gt;PropertyPageReference pageLinkProperty = properties["PageLink"] as PropertyPageReference;&lt;br /&gt;if (!pageLinkProperty.IsNull) { _pageLink = pageLinkProperty.PageLink;}&lt;br /&gt;base.InitializeData(config, properties);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114776528318882521?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114776528318882521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114776528318882521' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114776528318882521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114776528318882521'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/05/making-custom-properties-aware-of.html' title='Making Custom Properties aware of their context in EPiServer'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114612067151381340</id><published>2006-04-26T23:40:00.000-07:00</published><updated>2006-04-26T23:51:56.156-07:00</updated><title type='text'>Report Server: The report server cannot decrypt the symmetric key</title><content type='html'>If you ever come across this error message in SQL Server 2000 Report Server, it is usually caused by one of two things. Either you have recently changed the account that is used to run the ReportServer service, in which case you should follow this article:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://support.microsoft.com/kb/842421"&gt;http://support.microsoft.com/kb/842421&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;or you installed or uninstalled some part of .net 2.0 recently, in which case you might have to run the rsactivate tool. go to the directory:&lt;br /&gt;C:\Program Files\Microsoft SQL Server\MSSQL\Reporting &lt;br /&gt;Services\ReportServer\  &lt;br /&gt;or the equivalent program path on your computer and type&lt;br /&gt;rsactivate -r -c RSReportServer.config&lt;br /&gt;&lt;br /&gt;if rsactivate is not in your path (which it should be after an install) you will find it in &lt;br /&gt;C:\Program Files\Microsoft SQL Server\80\Tools\Binn&lt;br /&gt;&lt;br /&gt;or whatever path is the equivalent on your machine&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114612067151381340?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114612067151381340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114612067151381340' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114612067151381340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114612067151381340'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/04/report-server-report-server-cannot.html' title='Report Server: The report server cannot decrypt the symmetric key'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114303774267239589</id><published>2006-03-22T06:27:00.000-08:00</published><updated>2006-03-23T09:05:08.096-08:00</updated><title type='text'>Thinking Ruby in C# 2.0 ?</title><content type='html'>foreach(string chosenstring in myList.FindAll(new Predicate&amp;lt;string&amp;gt;(delegate(string s)&lt;br /&gt;            {&lt;br /&gt;                return s.Length&amp;gt;10;&lt;br /&gt;            })))&lt;br /&gt;            {&lt;br /&gt;                    Console.WriteLine("the following string is long: " +chosenstring);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The preceding code will run through a list containing strings and output the strings longer than 10 words. &lt;br /&gt;&lt;br /&gt;read it and weep&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114303774267239589?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114303774267239589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114303774267239589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114303774267239589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114303774267239589'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/03/thinking-ruby-in-c-20.html' title='Thinking Ruby in C# 2.0 ?'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114137998158886608</id><published>2006-03-03T01:53:00.000-08:00</published><updated>2006-03-22T06:31:04.486-08:00</updated><title type='text'>Setting asp:Label texts too early</title><content type='html'>Just discovered that if you have method calls to the code-behind (typically a protected method in the codebehind called between &lt;% %&gt; tags) You cannot alter The text property on labels in that method.&lt;br /&gt;&lt;br /&gt;This probably extends to manipulating any property on any webcontrol defined in the code-front. I guess it's just too early.&lt;br /&gt;&lt;br /&gt;when stepping through the code The label had its original value (which obviously would have been read/instantiated in the code-front), I replaced it with a new value and when the page rendered it had turned back to the original value.&lt;br /&gt;&lt;br /&gt;I guess this means that the code-front is read twice, before method calls in it are handled, and after.  Is it just me that find this weird?&lt;br /&gt;&lt;br /&gt;The fix to my problem was easy, I just placed the method-call in Page_Load, so no biggie, but I was stumped on it for a while&lt;br /&gt;&lt;br /&gt;Edit: OK, so I might have missed the obvious, but of course the ViewState is copied back.. and overwrites my changes. Since ViewState is copied just before Page_Load, The earliest you can write to weeb-controls is page_load&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114137998158886608?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114137998158886608/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114137998158886608' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114137998158886608'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114137998158886608'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/03/setting-asplabel-texts-too-early.html' title='Setting asp:Label texts too early'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-114102647246120620</id><published>2006-02-26T23:29:00.000-08:00</published><updated>2006-02-26T23:47:52.496-08:00</updated><title type='text'>VS2003: "unable to read the project file" "the system cannot find the file specified"</title><content type='html'>OK, so I've had this nuissance for a week before I finally snapped and had to fix it: Every time I started Visual Studio and opened up my project I would get an error message saying something to the effect of "unable to read the project file" "the system cannot find the file specified"...&lt;br /&gt;&lt;br /&gt;The web project would not be loaded, only be displayed as "unavailable" and any project with bindings to the web project (IE. the test project) would lose their bindings.&lt;br /&gt;&lt;br /&gt;The drill would be to delete the unavailable project and add it anew through file -&gt; add project -&gt; from file. This would then fix the problem temporarily, except I would need to set the lost bindings again.&lt;br /&gt;&lt;br /&gt;If I tried to add the project from web I would get the error message stated above.&lt;br /&gt;&lt;br /&gt;So how does one solve such a predicament?&lt;br /&gt;&lt;br /&gt;Exit VS, &lt;br /&gt;Delete the .SUO file&lt;br /&gt;Start VS&lt;br /&gt;Set the source control that you lost&lt;br /&gt;Done, enjoy error free heaven&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-114102647246120620?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/114102647246120620/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=114102647246120620' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114102647246120620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/114102647246120620'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/02/vs2003-unable-to-read-project-file.html' title='VS2003: &quot;unable to read the project file&quot; &quot;the system cannot find the file specified&quot;'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113990850575510001</id><published>2006-01-05T01:10:00.000-08:00</published><updated>2006-02-14T01:15:05.776-08:00</updated><title type='text'>OK so I blew it</title><content type='html'>I ran out of steam mid-december, I tried to find other stuff i wanted to share with the world of programmers out there, I really really had heaps of stuff to do at work. and suddenly I needed to get xmas prezzies for everyone... jeez get off my back will you?&lt;br /&gt;&lt;br /&gt;Basicly I figured out that instead of writing twelve more posts that weren't interesting I'd take some time out and figure out new stuff to write about so that the quality of the blog wouldn't plummet.&lt;br /&gt;&lt;br /&gt;To all would-be christmas calendar writers out there: do yourselves a favor, have the calendar ready before december, coz december isn't as slow and easy as one would like to think.&lt;br /&gt;&lt;br /&gt;So instead of sweating it, I'll write when I want about what I want. &lt;br /&gt;So there&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113990850575510001?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113990850575510001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113990850575510001' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113990850575510001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113990850575510001'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2006/01/ok-so-i-blew-it.html' title='OK so I blew it'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113463610740499624</id><published>2005-12-15T00:22:00.000-08:00</published><updated>2005-12-15T00:41:47.416-08:00</updated><title type='text'>Christmas Calendar 11/24</title><content type='html'>This one goes out to all non-americans&lt;br /&gt;&lt;br /&gt;As we all know, dates should be represented on the format&lt;br /&gt;dd.mm.yyyy - or derivatives thereof.&lt;br /&gt;&lt;br /&gt;NOT&lt;br /&gt;&lt;br /&gt;mm.dd.yyyy&lt;br /&gt;&lt;br /&gt;so here is the case: Sql Server 2000 will, in its&lt;br /&gt;Enterprise Manager, display all dates on the format&lt;br /&gt;as defined by the regional settings of the local user &lt;br /&gt;looking at the database.&lt;br /&gt;&lt;br /&gt;both the Database and the Sql Server has settings for locale and&lt;br /&gt;language etc. but they are all overridden by the locale of the user.&lt;br /&gt;keep this in mind when, oh say, remoting into a server using some &lt;br /&gt;admin user to do stuff on the DB through E.M. &lt;br /&gt;&lt;br /&gt;You might just be editing dates the "wrong" way&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113463610740499624?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113463610740499624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113463610740499624' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113463610740499624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113463610740499624'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-1124.html' title='Christmas Calendar 11/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113498258454008846</id><published>2005-12-12T00:54:00.000-08:00</published><updated>2005-12-19T00:56:24.546-08:00</updated><title type='text'>Christmas Calendar 12/24</title><content type='html'>In javascript the "enabled" property is instead called the "disabled" property with opposite effect. How curius! Does this point at some underlying mentality on the part of the JS developers?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113498258454008846?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113498258454008846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113498258454008846' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113498258454008846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113498258454008846'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-1224.html' title='Christmas Calendar 12/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113447986321691400</id><published>2005-12-10T04:54:00.000-08:00</published><updated>2005-12-13T05:18:19.443-08:00</updated><title type='text'>Christmas Calendar 10/24</title><content type='html'>Array casting.&lt;br /&gt;&lt;br /&gt;I have stumped on this one in the past:&lt;br /&gt;Why can't I cast an array of one type to an array of another type?.&lt;br /&gt;&lt;br /&gt;I fill my ArrayList with nothing but strings, I need to pass the content as a simple string-array (maybe in conjuncture with some web-service). &lt;br /&gt;&lt;br /&gt;I call the ToArray(typeof(string)) on the arrayList and we should be done....&lt;br /&gt;&lt;br /&gt;.. almost anyway, I also have to typecast the Array returned into the string[] &lt;br /&gt;&lt;br /&gt;string[] stringArray = (string[])stringList.ToArray(typeof(string));&lt;br /&gt;&lt;br /&gt;ok, this works.. but what if my strings are already contained in a object array, such as would be returned from a call to the simple ToArray() function on ArrayList.&lt;br /&gt;&lt;br /&gt;would this work?&lt;br /&gt;&lt;br /&gt;object[] object_array = stringList.ToArray();&lt;br /&gt;string[] string_array = (string[]) object_array;&lt;br /&gt;&lt;br /&gt;sounds simple? well it is, .. it is too simple, so simple, in fact, that it won't work. You can't bulk-cast an array and all of its content in one go.&lt;br /&gt;&lt;br /&gt;(but wait, didn't we just do that above? .... no we didn't. The content was already cast into the correct form. That's how come even though we supplied the object type we still only got a generic Array back the generic Arrays content was correct. only the shell was needed to be explicitly cast into the correct form)&lt;br /&gt;&lt;br /&gt;so. what to do eh? &lt;br /&gt;do we have to settle for the old an known?&lt;br /&gt;&lt;br /&gt;for(int i = 0; i&amp;lt;object_array.Length; i++)&lt;br /&gt;{&lt;br /&gt;  string[i] = (string)object[i];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;not bloody likely! Let's instead use the Array.CopyTo() function!&lt;br /&gt;&lt;br /&gt;string[] string_array = new string[object_array.Length];&lt;br /&gt;object_array.CopyTo(string_array, 0);&lt;br /&gt;&lt;br /&gt;so there's two ways of array-cast &lt;br /&gt;Merry xmas to everyone :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113447986321691400?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113447986321691400/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113447986321691400' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113447986321691400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113447986321691400'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-1024.html' title='Christmas Calendar 10/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113446740880437600</id><published>2005-12-09T01:45:00.000-08:00</published><updated>2005-12-13T03:09:03.210-08:00</updated><title type='text'>Christmas Calendar 9/24</title><content type='html'>Why don't my 3.rd party DLL come along to play on my deployment server when I choose "Copy Project" on my web solution?&lt;br /&gt;&lt;br /&gt;If your web solution is layered into different projects with a separate DLL for, say, business logic. If your BL project needs DLLs, you need to put them into the web project Lib folder, add them to the project and reference them from the web-project. This way they will play along nicely!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113446740880437600?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113446740880437600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113446740880437600' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113446740880437600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113446740880437600'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-924.html' title='Christmas Calendar 9/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113411701352327822</id><published>2005-12-08T00:13:00.000-08:00</published><updated>2005-12-13T03:09:19.673-08:00</updated><title type='text'>Christmas Calendar 8/24</title><content type='html'>What to do when you want to bind more than one field into a dropdownlist?&lt;br /&gt;&lt;br /&gt;You've created your object, &lt;br /&gt;&lt;br /&gt;BEHOLD MY BEAUTIFUL OBJECT "MyObject" !!!&lt;br /&gt;&lt;br /&gt;and you want a Dropdown to contain, say, both the Id property and the Name property.&lt;br /&gt;&lt;br /&gt;"DOH" you might say, now I've got to create a new property that contains the textual representation of the Id and Name in the object.. "why oh why must my beautiful object depend on the whims of my presentation layer"&lt;br /&gt;&lt;br /&gt;fear not ye brave coders. the solution is nigh!&lt;br /&gt;&lt;br /&gt;write one of these beauts and you'll be set. &lt;br /&gt;&lt;br /&gt;DropDownList1.DataTextField = MyObject.Id &amp; ”-” &amp; MyObject.Name;&lt;br /&gt;DropDownList1.DataValueField = MyObject.Id;&lt;br /&gt;DropDownList1.DataBind();&lt;br /&gt;&lt;br /&gt;The &amp; is not to be confused with &amp;&amp; as in "logical AND". but is more like "AND concatenate THIS!! "&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113411701352327822?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113411701352327822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113411701352327822' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113411701352327822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113411701352327822'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-824.html' title='Christmas Calendar 8/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113403460319429053</id><published>2005-12-07T01:29:00.000-08:00</published><updated>2005-12-08T01:36:43.203-08:00</updated><title type='text'>Christmas Calendar 7/24</title><content type='html'>Say you need to get the last version before some point in time of a record from a DB that stores multiple versions of the same data timestamps, what would be the most efficient way?&lt;br /&gt;&lt;br /&gt;After testing a few things we arrived on this little beauty, simple yet effective.&lt;br /&gt;&lt;br /&gt;select * from tblMyTable a &lt;br /&gt;WHERE not exists &lt;br /&gt;( select 1 from tblMyTable a1 &lt;br /&gt;  where a1.version &gt; a.version and a1.id = a.id and a1.version &lt;= @pointInTime ) &lt;br /&gt;and a.version &lt;= @pointInTime )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;A trap one might blunder into is not narrowing the outer query by @pointInTime which would give you too many records back&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113403460319429053?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113403460319429053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113403460319429053' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113403460319429053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113403460319429053'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-724.html' title='Christmas Calendar 7/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113388045400034769</id><published>2005-12-06T06:44:00.000-08:00</published><updated>2005-12-06T06:47:34.010-08:00</updated><title type='text'>Happy happy joy joy</title><content type='html'>A: I would like to congratulate myself on passing on Microsoft certification exam 70-300 (.Net Architect)&lt;br /&gt;&lt;br /&gt;A: Thanks Andreas! That's so nice of you! But how did you know?&lt;br /&gt;&lt;br /&gt;A: Coz you just won't shut up about it.&lt;br /&gt; &lt;br /&gt;A: Aahh. That'd explain it!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113388045400034769?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113388045400034769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113388045400034769' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113388045400034769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113388045400034769'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/happy-happy-joy-joy.html' title='Happy happy joy joy'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113387993394087962</id><published>2005-12-06T06:38:00.000-08:00</published><updated>2005-12-06T06:38:53.966-08:00</updated><title type='text'>Christmas Calendar 6/24</title><content type='html'>Never ever ever ever ever ever ever ever ever ever ever ever ever ever &lt;br /&gt;declare Enums / constants in the business layer of an application (or any other conventional layer for that sake). &lt;br /&gt;&lt;br /&gt;Before you know it you will need to access those from a layer that doesn't have access to the business layer, and then my friend you are screwed. &lt;br /&gt;&lt;br /&gt;Put them instead in a util - project that is included into every other project, that way you won't have to use sql like "where ProjectStatusId = 23" in your dataaccess-code. &lt;br /&gt;&lt;br /&gt;The same goes for accessing application configuration settings. Write the code once in a util-project and walk away knowing that it's there.&lt;br /&gt;&lt;br /&gt;"but why not just put this stuff into the domain model" - you ask...&lt;br /&gt;1) because Andreas says so&lt;br /&gt;2) because more stuff gets configured through config settings and constants than just domain logic. keep it clean and DRY!.. take it out into a separate (small and cute) util-project&lt;br /&gt;&lt;br /&gt;how does the lyrics to that song lyric go?&lt;br /&gt;&lt;br /&gt;--"you got to keep 'em separated  ..  *DÆNH DÆNH DÆNH DÆNH"&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113387993394087962?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113387993394087962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113387993394087962' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113387993394087962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113387993394087962'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-624.html' title='Christmas Calendar 6/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113379160603037073</id><published>2005-12-05T06:03:00.000-08:00</published><updated>2005-12-05T06:54:16.143-08:00</updated><title type='text'>Christmas Calendar 5/24</title><content type='html'>A quick one today:&lt;br /&gt;&lt;br /&gt;If you want controls in datagrids to be available in the viewstate, they must be declared and initialised within the page_init. If you want access to calculated values in the footer of a datagrid, you need to make sure the controls containing those values are initialised in page_init or you're screwed.&lt;br /&gt;&lt;br /&gt;This is a result of the TrackViewState method on DataGrids being called just before the Load event is fired. The TrackViewState method does exactly what you would expect, it tracks the viewstate, ie. it puts all its controls into the ViewState&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113379160603037073?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113379160603037073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113379160603037073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379160603037073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379160603037073'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-524.html' title='Christmas Calendar 5/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113379137100061091</id><published>2005-12-04T05:54:00.000-08:00</published><updated>2006-01-04T03:27:46.056-08:00</updated><title type='text'>Christmas Calendar 4/24</title><content type='html'>When working in .Net, you might wonder why it doesn't round off numbers the same way you learned in school. &lt;br /&gt;&lt;br /&gt;.Net uses what is called "Bankers rounding" which means that in the event of a tie (e.g. 2,5) it will round towards the nearest even number, so &lt;br /&gt;&lt;br /&gt;Math.Round(2.5) --&gt; 2&lt;br /&gt;Math.Round(1.5) --&gt; 2&lt;br /&gt;&lt;br /&gt;This is due to the fact that consistently rounding up (as you might remember from your schooldays) will result in a strictly increasing rounding error for all "tied" numbers (.5). Since banks typically have quite a few transactions each day, the term "strictly increasing rounding error" sounds bad to them. &lt;br /&gt;&lt;br /&gt;why does .Net provide this rounding as default? -dont know dont care&lt;br /&gt;&lt;br /&gt;what do we do about it? - do know do care:&lt;br /&gt;define and use MidpointRounding.AwayFromZero as parameter in a custom util method.&lt;br /&gt;&lt;br /&gt;public enum MidpointRounding&lt;br /&gt; {&lt;br /&gt;  ToEven, AwayFromZero&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;public class Util&lt;br /&gt;{&lt;br /&gt;public static double Round( double number, int digits, MidpointRounding roundingType) &lt;br /&gt;  { &lt;br /&gt;   if (roundingType == MidpointRounding.AwayFromZero)&lt;br /&gt;   {&lt;br /&gt;    double multiplyValue = Math.Pow( 10, digits ); &lt;br /&gt;    double dRound = Math.Floor(((number*2*multiplyValue)+1)/2)/multiplyValue; &lt;br /&gt;    return dRound;&lt;br /&gt;   }&lt;br /&gt;   else&lt;br /&gt;   {&lt;br /&gt;    return Math.Round(number,digits);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113379137100061091?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113379137100061091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113379137100061091' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379137100061091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379137100061091'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-424.html' title='Christmas Calendar 4/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113379078959189138</id><published>2005-12-03T17:11:00.000-08:00</published><updated>2005-12-05T05:54:47.433-08:00</updated><title type='text'>Christmas Calendar 3/24</title><content type='html'>Modulus operator (%)&lt;br /&gt;&lt;br /&gt;It might be obvious to some, especially those who hva studied maths (and remember the curriculum) that the modulus operator can return negative values.&lt;br /&gt;&lt;br /&gt;The modulus operator will return an answer within 0 +- n &lt;br /&gt;&lt;br /&gt;For instance: 13 % 10 = 3&lt;br /&gt;but -13 % 10 = -3&lt;br /&gt;&lt;br /&gt;This is different from for example ruby's implementation that will return 7 on that same query. try it yourself.&lt;br /&gt;&lt;br /&gt;if you want (imho) logical modulus, write your own util-method: &lt;br /&gt;public static int Mod(int i, int n){&lt;br /&gt; return (((i % n) + n) % n)&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Thanks to Erlend W. Oftedal for help on this post&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113379078959189138?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113379078959189138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113379078959189138' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379078959189138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113379078959189138'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-324.html' title='Christmas Calendar 3/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113351776740369348</id><published>2005-12-02T01:57:00.000-08:00</published><updated>2005-12-02T02:02:47.403-08:00</updated><title type='text'>Christmas Calendar 2/24</title><content type='html'>Iterating enums&lt;br /&gt;&lt;br /&gt;it's not trivial to iterate enums in .Net 1.1 &lt;br /&gt;&lt;br /&gt;A solution is to do the following (iterating MyEnum):&lt;br /&gt;foreach(string enumstring in Enum.GetNames(typeof(MyEnum)))&lt;br /&gt;{&lt;br /&gt;MyEnum enumItem = Enum.Parse(typeof(MyEnum),enumstring);&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This will only work if the enum has a different GetHashCode() for all the&lt;br /&gt;items in it. Otherwise only the first item with a given hashcode will be used (multiple times).&lt;br /&gt;&lt;br /&gt;This is due to the ridicoulus fact that Enum.Parse does not match the name given with the enum's ToString (as one would expect) but rather matches on the hashcodes...&lt;br /&gt;&lt;br /&gt;go figure!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113351776740369348?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113351776740369348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113351776740369348' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351776740369348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351776740369348'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-224.html' title='Christmas Calendar 2/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113351743467849520</id><published>2005-12-01T01:44:00.000-08:00</published><updated>2005-12-05T06:28:36.590-08:00</updated><title type='text'>Christmas calendar 1/24</title><content type='html'>Today I will talk about something I've been stumped on a few times. It's sooo easy, but it's also easy to forget, so here goes:&lt;br /&gt;&lt;br /&gt;DateTime Accurracy&lt;br /&gt;&lt;br /&gt;A) The .Net DateTime type holds its accurracyin ticks: each tick is 100 nanoseconds.&lt;br /&gt;IE. there are 10000 ticks each millisecond. &lt;br /&gt;&lt;br /&gt;B) The Sql DateTime type only holds accurracy down to three milliseconds.&lt;br /&gt;&lt;br /&gt;C) The .Net DateTime Type does *not* output its milliseconds in the standard ToString()&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;These three points work in unison to make it hard to work with datetimes in .net. One could always just use SqlDateTime, but this datatype is hopelessly useless (no functionality).&lt;br /&gt;Frequently I find I wish we just stored the ticks in the database and did the conversion manually in my current project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113351743467849520?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andreascode.blogspot.com/feeds/113351743467849520/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=19511232&amp;postID=113351743467849520' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351743467849520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351743467849520'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/12/christmas-calendar-124.html' title='Christmas calendar 1/24'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-19511232.post-113351662785730822</id><published>2005-11-29T01:34:00.000-08:00</published><updated>2005-12-05T06:37:29.360-08:00</updated><title type='text'>Hello World</title><content type='html'>This will be my third attempt at actually keeping a blog alive for more than a few months. This time I will try to keep it fairly technical and up to date with problems I encounter and (hopefully) their solution. &lt;br /&gt;&lt;br /&gt;Mostly, this blog will contain .Net stuff as this is the world I live in at the moment, but I hope to cram in revelations on TDD and Agile development as I get more into these methodologies in time.&lt;br /&gt;&lt;br /&gt;So.. I don't expect people to actually read my blog, but if you read this now, then I was wrong and you were right in coming here. (hopefully)&lt;br /&gt;&lt;br /&gt;Anyhoo...&lt;br /&gt;I will try and start off with an exercise in self-discipline and present a different christmas calendar containing 24 of my most recent blunders (and their solutions). &lt;br /&gt;&lt;br /&gt;As I don't make any claims of Godhood within the field, please feel free to correct me where I'm wrong or provide your own blunders where appropriate. Just remember to keep the tone light and somewhat entertaining. I will excercise my right to delete posts that are rude, abusive, or [insert bad adjective here] language. But all posts written with good intent will live on in eternity. (no matter how bad light they might put me in) After all, we're all happy amateurs in a field that has no defined boundaries of professionalism.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/19511232-113351662785730822?l=andreascode.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351662785730822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/19511232/posts/default/113351662785730822'/><link rel='alternate' type='text/html' href='http://andreascode.blogspot.com/2005/11/hello-world.html' title='Hello World'/><author><name>Andreas</name><uri>http://www.blogger.com/profile/11982370182573056694</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://bp0.blogger.com/_gWibonIMmIU/R_ADJmbQ7LI/AAAAAAAACxc/VX5vBPeDwP0/S220/andreas.jpg'/></author></entry></feed>
