Skip to main content

Posts

Showing posts with the label net

Defensive Programming & Argument Validation

  The other day I found myself debugging the dreaded NullReferenceException “Object Reference not set to an instance of an object” on a piece of code written by a fairly Senior Developer.   If you’ve been developing on .NET for more than 5 minutes then I’m sure you have come across this in your daily work and it is incredibly frustrating to try and debug. With this post I hope to demonstrate how by using Defensive Programming you can make your API’s more robust and as a result reduce the number of bugs in your code. If you’re a bit hazy on Defensive Programming and it’s cousins then I suggest you read the following: Defensive Programming Fail Fast Design by Contract (DbC) Validating method arguments for public methods should be a very simple concept to grasp and for most skilled developers is a  as natural as writing If statements. The guiding principle I follow is to trust no single input and ensure that code only executes when the supplied arg...

ASP.NET MVC Beta - HtmlHelper.TextBox change

I've just come across a minor change which caused the Value on my TextBox's to be set to "System.Collections.Generic.Dictionary`2[System.String,System.Object]" The HtmlHelper.TextBox method has changed. The previous (MVC Preview 5) method overloads were HtmlHelper.TextBox(string name) HtmlHelper.TextBox(string name, object htmlAttributes) HtmlHelper.TextBox(string name, string value) HtmlHelper.TextBox(string name, IDictionary htmlAttributes) HtmlHelper.TextBox(string name, string value, object htmlAttributes) HtmlHelper.TextBox(string name, string value, IDictionary htmlAttributes) These have been changed to: HtmlHelper.TextBox(string name) HtmlHelper.TextBox(string name, object value) HtmlHelper.TextBox(string name, object value, object htmlAttributes) HtmlHelper.TextBox(string name, object value, IDictionary htmlAttributes)