Archives / 2010 / June
  • Budding Versus Festering Code

    This is in response to Michael Feathers’ recent post on Festering Code Bases and Budding Code Bases. Certainly the default tooling in the Visual Studio space has, until recently, made it dramatically easier to add code to an existing class than to create a new class.  However, tools like ReSharper have a large impact on this, and can make it extremely easy to create new classes, put them in their own files, and move those files where they are supposed to go with just a few keystrokes (and VS2010 is coming along in some of these areas as well).  So, I think there is a trend in the tooling to make the cost of budding less - it would be interesting to add something to the IDE that … more

  • Disable Hibernation on Servers

    Here’s a quick tip if you should find several GB of your system drive taken up with hiberfil.sys on a production server machine (as I recently did with a virtual server with a very small C partition) – Disable Hibernation. Disable Hibernation 1. Open a command prompt as administrator 2. Run this command: powercfg –h off 3. Done! The hiberfil.sys file should immediately disappear.  This also works on desktop computers that never use hibernate, of course.  Thanks to SpearMan for the tip.  I’ve only tested this on Windows Server 2008, but I’m pretty sure it will work on most modern versions of Windows (7, Vista, 2008 R2, etc.). more

  • Default Encoding of Strings in ASP.NET MVC 2

    If you have ASP.NET MVC 1 code you are moving to ASP.NET MVC 2 (and ASP.NET 4) you are likely to encounter a problem in which your application starts displaying encoded HTML on the page rather than the actual results of that HTML (e.g. you see <a href … /> instead of a hyperlink). One of the greatest features added to ASP.NET 4 is a new way to render content that is encoded by default in your .aspx/.ascx pages/views.  This new syntax uses <%: Model.SomeString %> instead of the ever-popular <%= Model.SomeString %> way of doing it.  Note the third character is now a : not an =.  It actually takes up a tiny bit less horizontal space – isn’t that nice of the … more

  • Tagging Releases in Source Control

    A best practice when you’re using source control is to tag your releases.  What does this mean, exactly?  If you’re following the relatively standard non-distributed source control repository folder structure of having root folders for: branches tags trunk then it means simply making a copy of the current state of the system when you did your release.  Here’s how to do it using Subversion (SVN) and the TortoiseSVN client, both popular free tools for source control management. Step 1: Test and Deploy Your Application Do whatever it is you do to deploy your application.  Maybe you create an EXE package.  Maybe you FTP a web site to production.  Whatever … more

  • Moving a Certificate Between Web Servers

    I’m in the process of moving Lake Quincy Media’s web site from one server to another, and since it uses SSL to secure users’ data, I had to move the certificate to the new server as part of the server move.  Fortunately, this process is quite painless.  First, you need to export the certificate to a .pfx file and give it a password, using these steps: 1. Start, Run, MMC (I did it as administrator) 2. Go to File –> Add/Remove Snap-in 3. Click on Certificates and Add 4. You want Local Computer.  Click Finish 5. Click OK to close the Add/Remove Snap-in wizard 6. Expand the Certificates (Local Computer) tree. 7. Open the Personal – Certificates section. 8. You should … more

  • SQL Server Error User Group or Role Already Exists in the Current Database

    If you restore a database and then try to login to it, you’re likely to run into this wonderful SQL Error: User, group, or role ‘whatever’ already exists in the current database (Microsoft SQL Server, Error: 15023). Unfortunately, using Sql Management Studio alone doesn’t seem up to the task of correcting this problem.  You have to drop down to calling esoteric stored procedures (who needs a GUI to actually manage users and logins, right?). Searching for this error at least yields many results like these.  I especially like the second one whose title ends with ‘Aarrgghh!!’ which led to me clicking it since it represented my current thoughts on the matter quite succinctly. In … more

  • Great Uses of Using Statement in C#

    In my last post about testing emails in .NET, I noted the use of the using statement to ensure safe usage of the IDisposable SmtpClient and MailMessage objects.  This is the typical usage of the using statement, but you can take advantage of this statement’s behavior for other scenarios as well, resulting in cleaner code. Consider the scenario where you want to perform some kind of pre- and post- processing around an arbitrary block of code.  The simplest scenario I know of is when you want to time some code, using the stopwatch class.  If you want to perform basic stopwatch usage, you can write some code like this (borrowed from the stopwatch MSDN docs): public … more

  • Testing Email Sending

    Recently I learned a couple of interesting things related to sending emails.  One doesn’t relate to .NET at all, so if you’re a developer and you want to easily be able to test whether or not emails are working correctly in your application without actually sending them and/or installing a real SMTP server on your machine, pay attention.  You can grab the smtp4dev application from codeplex, which will listen for SMTP emails and log them for you (and will even pop-up from the system tray to notify you when it receives them) – but it will never send them.  Here’s what the notification looks like: The other interesting tidbit about emails that is specific to .NET is that the … more

  • DevConnections Spring 2010 Speaker Evals and Tips

    As a conference speaker, I always look forward to hearing from attendees whether they felt my sessions were valuable and worth their time.  It’s always gratifying  get a high score, but of course it’s the (preferably constructive) criticism that’s key to continued improvement.  I’m by no means the best technical presenter around, and I’m always looking for ways to improve. I’ve recently spoken at a few events, including TechEd and an Ohio event called Stir Trek.  DevConnections was actually back in April, but they’re just getting their final evals out to speakers.  TechEd, of course, does online evals so immediately after your talks you can see what people … more