Visual Studio 2008 Hangs When Debugging ASP.NET App

I’ve been doing some work with ASP.NET MVC but was having periodic issues with Visual Studio 2008 hanging (freezing / becoming unresponsive) when I tried to run my web application with debugging.  The problem only occurred with a specific web project.

I tried deleting the Temporary ASP.NET Files (%userprofile%\AppData\Local\Temp\Temporary ASP.NET Files) but that did not solve the problem.

I tried deleting the obj folder.  No luck.

I tried waiting it out one evening.  I eventually feel asleep and when I awoke sometime in the middle of the night, my web app was happily waiting for input and Visual Studio debugging was completely responsive.  That proved to be a temporary salve.

showallfiles The problem resurfaced again a few days later and I finally figured out the problem with my uncooperative debugger.  I have a folder containing approximately 20,000 images that are not included in the Visual Studio web project but are sitting in a directory in the web site.  I had turned on "Show All Files" in Solution Explorer to add some script files into the project.  When "Show All Files" is off, F5 (Start Debugging) works like  champ.  When "Show All Files" is on, Visual Studio becomes unresponsive.  In reality it is not "frozen" but simply taking a very long time to process those 20,000 image files.

Mystery solved.

Forms Not Submitting With Watir?

Watir, pronounced water, is an open-source (BSD) library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.

Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.

A great use for Watir is to automate tedious form filling during development / developer testing.  Let’s say you have a simple form like the following to submit a search query to Google:

<form id="search_form" action="">
  <input name="q" value="derekhat" />
  <input type="submit" name="submit" />

The Ruby code to submit a form is pretty simply:

Browser.goto "file:///C:/Users/derek/Desktop/submit.html";
Browser.form(:id, "search_form").submit;

The only problem is that this won’t work in this case.  The reason:  there’s an input field called submit that hides the form’s submit method.  The workaround is easy:

Browser.goto "file:///C:/Users/derek/Desktop/submit.html";
Browser.button(:name, "submit").click;

Happy testing!

Fix for WordPress XMLRPC 500 Internal Server Error

One of my WordPress-based sites ( was not working when I tried to publish posts containing images from Windows Live Writer.  I was getting a 500 Internal Server Error.

I was able to fix the problem by making a small change to the database.

The Error Message

I enabled Failed Request Tracing in IIS7 to find out what was happening server-side to cause the HTTP 500 error.  I discovered that the PHP script was trying to insert a row into the wp_posts table with a value of -1 in the post_parent column:

WordPress database error Out of range value for column ‘post_parent’ at row 1 for query INSERT INTO `wp_posts` (`post_author`,`post_date`,`post_date_gmt`, `post_content`, `post_content_filtered`, `post_title`, `post_excerpt`, `post_status`, `post_type`, `comment_status`,`ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_parent`,`menu_order`,`post_mime_type`,`guid`) VALUES (‘1′,’2009-07-15 14:37:14′,’2009-07-15 17:37:14′,”,”,’2827426439_7b744abd30_m.jpg’, ”, ‘inherit’, ‘attachment’,’open’,’open’, ”, ‘2827426439_7b744abd30_m-jpg’,”,”,’2009-07-15 14:37:14′,’2009-07-15 17:37:14′,’-1′, ‘0’, ‘image/jpeg’, ‘’) made by wp_xmlrpc_server->wp_xmlrpc_server, IXR_Server->IXR_Server, IXR_Server->serve, IXR_Server->call, wp_xmlrpc_server->mw_newMediaObject, wp_insert_attachment
ErrorCode 5

Apparently the database didn’t like that…  I investigated further and discovered that the post_parent column in my database was set to BIGINT UNSIGNED.  In other words, that database column could not hold the value -1 (unsigned integers are zero or higher).

Some Sanity Checking

I checked several other WordPress databases that I control and found that post_parent column is not UNSIGNED in any of my other WP databases.

So why the difference?  All my other databases were created with earlier versions of WordPress and upgraded.  The database in question, however, had been created with the latest WordPress release (2.8 at the time).  So I popped open the PHP file that defines the database (schema.php) and discovered:

post_parent bigint(20) unsigned NOT NULL default ‘0’,

What’s Going On Here?

When the XMLRPC script uploads an image (called an attachment in WordPress), it uploads it with a post_parent of -1.  Then after the post is created, the script updates attachments with post_parent=-1 with the actual ID of the freshly created post.

My guess is that a developer on the project decided to update the schema to UNSIGNED because posts do not have negative values for IDs and the post_parent column references a post ID.  Obviously that developer did not realize the special use case in xmlrpc.php.

How Do I Fix This?

Fortunately the workaround is easy.  Just run the following database query to change the data type on the post_parent column:

ALTER TABLE wp_posts CHANGE post_parent post_parent BIGINT;

If you don’t know how to run queries against your MySQL database, well, this is a good time to learn.  I did it at the command line on my 64-bit Windows server:

cd "C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\"

mysql.exe –u root -p
Enter password: ***********************

Welcome to the MySQL monitor.  Commands end with ; or \g.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> use crowdspace
Database changed
mysql> ALTER TABLE wp_posts CHANGE post_parent post_parent BIGINT;

The process is similar on a Linux box.  I’m going to go out on a limb here and assume that you can figure out how to run mysql on Linux if you’re running your own Linux server.

If you’re using a shared web hosting service, you should be able to use a web interface such as phpMyAdmin to run this command.

That’s all it took to fix the problem for me.  Happy blogging!

The Art and War of Estimating and Scheduling Software

In my experience, the majority of estimates and schedules for software development projects are derived from hunches, guesswork, and gut instincts.  We say things like “that should take about 4 hours of work” without backing it up with data.  And we set timelines based on those estimates without adjusting for past accuracy in estimating.  And what about the tendency of the customer / stakeholder to change scope midstream?  That should drive how big the “buffer” is in the schedule for changing requirements.

I’m as guilty as the next person in many cases.  I fight an internal battle on this issue.  Part of me wants to just be a carefree developer with little to no regard for estimates.  I dare say that my time as a computer science student was when I got stuck in that trap.  Nobody taught me to estimate my work, let alone track the accuracy of my estimates over time.  I usually had ample time to do assignments and the code flowed easily for me so I never really worried about how long I spent working on things.  [In recent years, I know that people like Rick Wightman at the University of New Brunswick have been working on teaching students how to think more like professional developers.]

The professional developer in me knows that good estimates are essential to everyone in the development chain.

The businessperson in me cherishes accurate estimates.

ACM Queue has an interview with Joel Spolsky in which he talks a bit about evidence-based scheduling (which apparently is somehow supported in FogBugz):

In evidence-based scheduling, you come up with a schedule, and a bunch of people create estimates. And then, instead of adding up their estimates – instead of taking them on faith – you do a little Monte Carlo simulation where you look at what speeds developers had in the past, vis-à-vis their estimates. You use that same distribution of probabilities, as we call them, that you had in the past and run a simulation of all of your futures. What you get, instead of a date, is a probability distribution curve that shows the probability that the product will ship on such-and-such a date.

Nice!  I need to try that.  Sounds so much better than just using spreadsheets to track history.

What’s most interesting and useful about tracking estimate-to-actual history on a per-developer basis is that you get data about how accurate the hunch / gut instinct of each person really is.  This is so much more powerful than just collecting team or project based accuracy.  Of course there will be outliers in the data, like when a developer who does a lot of similar tasks has to estimate something new or unrelated.

I asked a friend who is a project manager that I respect (and trust) to comment on this.  (I was wondering if there was a more popular term than “evidence-based scheduling” or other good tools to support it.) At his old job he used to teach an estimating course for developers.  Check out the part I highlighted:

Well when you run a project you have a bunch of planned dates (when are you planning to be done), and you are really supposed to keep track of actual dates (when did the work actually finish).  If you are really keen (and perhaps have a database to track this by resource -and perhaps by technology and task type)… you should be able to form some projections on developers… I.e. Billy always takes twice as long to do a design but he does a detailed job so the coding goes twice as fast.  You can use this information to do a gut check on teams too… but Joel is right … these estimates are as complex as the people who are on the teams and the types of tasks they are working on.  There is also the issue of doing something for the first time… very hard to estimate.  It is only when you do something multiple times that you get good at estimating… and only if you are looking back on your estimates looking for trends.  What Joel is describing is putting some trends to the old estimate / vs. actuals data.

Not sure what to call it.  But PMs are always trying to log history of missing or hitting deadlines and you very quickly get a sense of which developers have good estimates, and which developers you need to double, triple, etc… On my last project I had a developer tell me something would be able to get something done by Friday of that week and it actually took about 3 months of 8 people full time… 😉  I’ve heard the statistic of 8:1 (fastest developer to slowest developer).

To my memory, I have never had a developer highlight his/her accuracy in estimating on a resume or during an interview.  That would be an interesting thing to do.  It would blow me away if someone told me they had a spreadsheet with their personal estimation accuracy showing their estimates-to-actuals history.  That would be an impressive artifact!

Cookieless Session with ASP.NET Ajax and Web Services

I just discovered a little snag when calling session-enabled ASMX web services from ASP.NET Ajax using cookieless session tracking (hat tip to Guy Barrette for raising the issue).  Here’s the scenario:  You are using cookieless sessions and want to call a web service in the same web app from JavaScript code.  With cookieless session state, you get a URI like this for your web page:


The URI for the web service would then look like this:


You can add an ASP.NET Ajax service reference to the web service declaratively in the <asp:ScriptManager> control or programmatically like this:

ServiceReference sr = new ServiceReference(“WebService.asmx”);

The reference is using a relative path so everything should be fine since default.aspx and WebService.asmx are both at the same location.

If you look at the source of the resulting web page, you’ll find a script tag that is pulling down a JavaScript definition for a proxy to be used to call the web service:

<script src=”WebService.asmx/js” type=”text/javascript”></script>

The script tag is using a relative path so everything should still be fine.  But if you try to call the web service from JavaScript, it doesn’t work:


Take a look at the script produced by WebService.asmx/js (click image to enlarge):


The second-to-last line sets the path to the web service without including the session ID in the URI:


You can work around this by resetting the path to the web service yourself.  For example, the following works:

function CallService()
    ws = new WebService();

Alternatively, you can invoke the web method using WebServiceProxy.invoke():

Sys.Net.WebServiceProxy.invoke(‘WebService.asmx’, ‘HelloWorld’,
    false,{}, SucceededCallback, null,”User Context”,1000000);

I prefer the first approach.  In both cases you are explicitly providing the URI for the web service because the generated proxy object does not include the session ID in the URI.

Multiple Mouse Pointers in Windows

The Microsoft Windows MultiPoint Software Development Kit (SDK) helps developers create programs that enable the use of multiple mice on a single computer.

This is really neat.  It will be a big help if you are working on same-room collaboration systems.  It also makes it plausible to port applications to large touch systems like wall displays or tabletop interfaces like the Microsoft Surface.  In the past it has been difficult to move an application to a touch-based interface because users keep “stealing” the mouse cursor from each other.  Presumably with this SDK you can work around that problem.  (Is it just happy coincidence that this is coming out around the same time as the Surface?)

This SDK came out of Microsoft Research but has been transferred to an education products group.  There’s currently a single blog post from the team if you want to follow along:

POSTing to a webpage and using it’s response (HttpWebRequest and HttpWebResponse)

You might encounter a situation where you need to Post to a web page and read it’s

Here’s a function that uses System.Net.HttpWebRequest and System.Net.HttpWebResponse
to do just that.

      ' Usage:
      '   Dim xmlDoc As Xml.XmlDocument
      '   xmlDoc.Load(MakeHttpRequest( _
                           "request=listPersons&filter=last(a*)", _
                           "/requestManager.php", _

      Protected Function MakeHttpRequest(
                                   ByVal data As String, _
                                   ByVal url As String, _
                                   ByVal contentType As String) _
                                   As System.IO.Stream
        Dim retVal As System.IO.Stream 
        Dim httpRequest As System.Net.HttpWebRequest 
        Dim httpResponse As System.Net.HttpWebResponse 
        Dim encoding As New System.Text.UTF8Encoding
        Dim uri As New System.Uri(url) 
        Dim postBytes As Byte() postBytes = encoding.GetBytes(data)      
        httpRequest = CType(System.Net.HttpWebRequest.Create(uri), _
        httpRequest.ContentLength = postBytes.Length 
        httpRequest.Method = "POST" 
        httpRequest.ContentType      = contentType 
        Dim postStream As System.IO.Stream = _
        postStream.Write(postBytes, 0, postBytes.Length) 
        httpResponse = CType(httpRequest.GetResponse(), System.Net.HttpWebResponse) 
        retVal = httpResponse.GetResponseStream()
        Return retVal
      End Function

Variation: If the webpage you are calling expects xml you could easily replace and
pass a valid xml string as data
httpRequest.ContentType = "application/x-www-form-urlencoded"

httpRequest.ContentType = "text/xml"

You could even go further and return an xml document if the expected datatype is

ASP.NET Membership and passwordStrengthRegularExpression

by Sebastien Aube

Membership in the .NET framework 2.0 allows you to add security to your application with little to no code.

When trying to enforce strong password rules in our church software I encounteredan interesting problem.

At first I modified the web.config by adding the following line to our membershipprovider section.


RegEx explained: 8 characters or more in length, at least 1 lowercase letter,at least 1 character that is not a lower letter.

I removed:


After some testing I found that even when following the password rules, a passwordchange would fail.

The ChangePassword control, which is part of the Login suite of controls, doesn’tgive you any information as to why the password changed failed.

After a few reviews of my RegEx and confirming that the syntax is correct in codeand with some useful online regular expression testers (see links below), I triedchanging the password using the following code:

MembershipUser mUser = Membership.GetUser(); //gets the current logged in user
//change the password
mUser.ChangePassword(mUser.GetPassword(), “invalidpassword”);

That caused the following exception: System.ArgumentException: Non alpha numeric charactersin ‘newPassword’ needs to be greater than or equal to ‘1’.

So I added this line:


And our password complexity rule started working properly.

I won’t start a debate on the merit of setting the minimum required non alphanumericcharacters (say that ten times) to 1, but hopefully this will help someone somewheresome time.


JavaScript Regular Expression Tester

.NET Regular Expression Tester

How to check for a network connection in .NET 2.0 (C# or VB)

To check for a network connection in .NET 2.0 use this:


To monitor a change in IP address or a change in network availability, use the events from the NetworkChange class: