Monday, August 22, 2005

Copying Doth Not A Debuggable Web Application Maketh

This week I was banging my head against the wall with a web project that I was working on.

The project manager had sent me a web project that he wanted me to work on. I copied the project and files into a directory (for sake of example xyzproject) under inetpub\wwwroot. Then, from within Visual Studio I opened the project from web: localhost/xyzproject. I made a bunch of changes and then tried to run the web app. I got an error that said that the application was not configured for debugging.

Following the instructions given by the error message, I went to my web.config and made sure that in the configuration section that debug was set to true (which it already was). I try to run the application, and again I'm presented with the error that the application is not configured for debugging. I can't even run the app in release mode.

After knocking my head against the wall for a while, I came to the realization that just copying a web project to wwwroot, does not make it recognized by IIS as a web application.

Here are the steps I took to fix it.

1. Open IIS
2. Go to the directory
3. Right-click the directory and choose properties
4. Next to the application name, there is a button with the caption "Create" (circled in red below). Press the button.

5. Click on the Configuration button (circled in red below)

6. Click on the Debugging tab. (circled in red below)

7. Make sure that the two Debugging Flags checkboxes are checked. (circled in red below)

7. Press Ok twice

Problem solved.

I hope this saves someone a slap and/or a butt-load of time.


Thursday, July 14, 2005

Peeking at An Iterator
C'mon, You Know You Want To

I'm currently designing a set of classes that will be used for parsing and importing data.

Being a devotee of Design Patterns, I am quite familiar with the Iterator pattern, and felt that it was the appropriate tool to apply to parsing rows in text-based files. Using an interator, rows could be parsed one character at a time, looking for field delimiters (for example, in comma delimited files, the field delimiter is a comma), and moving the data into into the appropriate field in a DataRow.

Strings in .NET already have an iterator associated with them. Strings implement the IEnumerable interface (from the System.Collections namespace), and therefore have a method called GetEnumerator. String's GetEnumerator method returns an instance of the CharEnumerator class (again, in System.Collections). As the name suggests, it iterates through through the characters in the string.

Iterators in .NET basically know 3 things:
  • how to view the current item in the aggregate (via the Current property).
  • how to move to the next item in the aggregate (via the MoveNext method)
  • how to determine whether there is anything left to iterate (via the return value of the MoveNext method)
Notice that Iterator does not, by default, provide a method for moving backwards: the pattern does suggest that it is possible to add this behavior, but says that there are some aggregates that cannot be iterated in reverse: for example, in ADO a forward-only cursor can only be iterated in one direction - forward.

I point this out because of an issue that I ran into while parsing Comma-Separated-Value (CSV) files. Certain CSV-formats surround character field data with double quotes: this allows commas to be be interpreted as part of the character field data. The side-effect of this is that if the character data needs to contain a double quote, you must put two double quotes right next to each other. For example, the following string:

I said to him, "Walter get off my foot." But he didn't listen.

would be:

"I said to him, ""Walter get off my foot."" But he didn't listen."

If you are reading a string one character at a time, and run into a double quote, you need to be able to look at the following character to determine whether the field data is ending, or whether the field data contains a double quote. The problem lies in the fact that to peek at the next character you need to move the Iterator forward one character: once you have done that, you cannot move backward.

Another quality of Iterators is that they maintain their own state (where they are in the aggregate: ie. which character position in the string the Iterator is pointing at). Because they maintain their own state, you can point multiple iterators at the same aggregate (ex. string). I can take advantage of this by:

If the Iterator I'm using to walk the string (ex. oIterator) is pointing at a double quote character

  • Creating another instance of CharEnumerator (ex. oPeekingIterator) that is pointing at the same character in the string.
  • Telling oPeekIterator to move forward one character by calling its MoveNext method
  • Read the character from oPeekIterator and see if it is a quote
  • Throw away the oPeekIterator
Note that moving in oPeekIterator does not change which character oIterator is pointing at: that's why you can throw it away. But how do you get an Iterator that points to the same place in the string? Take out your genetics kit and Clone it:

private char Peek(CharEnumerator oIterator) {
// Create a clone of the Iterator
// Since a clone is a copy, it will have the same state (will be pointing at the same character)

CharEnumerator oPeekingIterator = oIterator.Clone();

// Move the peeking iterator ahead one character


// return the current character
//(the character one-past the character that oIterator is pointing to

return oPeekingIterator.Current;


I know that error checking needs to be included in the routine, but I'm demonstrating a technique.

If you are not at least aware of Design Patterns, I would invite you to take a look, google it, even. It provides many Eureka! slaps and helps you avoid "How stupid could I be" slaps. Check it out ...

or else I'll have to slap you. ;-)

Friday, June 24, 2005

Why not start with a "How Stupid..."?

I have been working in both VFP and .NET lately, and recently had a "blonde" moment due to the fact that in VFP, everything is 1-based, whereas in .NET, everything is 0-based.

In VFP, if you want to search for a string within a string, VFP has a function called AT(), which returns the starting point of the string within the string. If the string cannot be found, AT() returns 0.

I wanted to create the .NET equivalent of the following VFP code:

   lcEmailMessageBody = "<html> ...."

   IF AT("<html",lcEmailMessageBody)>0 THEN

So I create the following .NET equivalent:

   lcEmailMessageBody = "<html>....";


Pretty straightforward, n'est-ce pas?

AAANNNN - wrong! When I ran this code, it only sent text mail.


Since strings in .NET are 0-based, a return value of 0 from IndexOf() means that the string was found in the first character of the string (character position 0 in the string). A return value of-1 means that the string is not found. so the proper if-statement is:


The funny part is that before I got slapped, I created another project to test it there, andthen asked a colleague if he got the same result on his computer. And as the words came out of my mouth, I realized the mistake, and braced myself for the slap.
Welcome to my blog!

My name is Rick Hodder and this is my blog.

A little about me. I'm a computer programmer by trade, but my interests/hobbies include:

Improv Comedy:
Both short form (a series of games like the show Whose Line Is It Anyway?) and long form (the audience is asked for words or phrases, after which a half hour show is created on the spot). I have taken classes and have been an ensemble performer at
Gotham City Improv in New York City. GCI was started by a group of "improv"ers from the famous LA improv group called "the Groundlings." I find improv a great way to "get out of my head" - its amazing where your mind can take you. I especially enjoy the fact that you don't prepare: no scripts, just what happens, and how you react to it. You create your own reality, and watch it change as other performers embellish. It's also great for thinking on your feet.

Community Theater:
I have been involved in theater since highschool. The latest theater that I have been involved with is the Ridgefield Theater Barn in Ridgefield, Connecticut. Being a consultant has taken me away from performing - community theater doesn't tend to have understudies, and consultants usually can't promise to be in town for the practices, let alone the performances. So what do actors do when they cant act anymore? That's right - they direct! Next year I hope to direct one of my favorite musical, Damn Yankees.

Music has been an important part of my life. I play the guitar, violin, and piano, but my favorite instrument is voice. I've always been a singer: my mom always encouraged it (like her I was in choirs). In college I toured the US and Europe with the Notre Dame Glee Club. I love playing guitar and singing at coffeehouses. I'm a huge fan of James Taylor.

Lately I have been taking a stab at writing music. I am using with Sonar 4 Producer, by Cakewalk Software.

Visual Foxpro
Visual Basic 6
Turbo Pascal

I am currently a C# programmer.

I really enjoy working with people in a learning setting. Teaching is in my blood. My mom was a teacher and later a vice-principal. My dad is a doctor who has taught medical school and led a medical residency program. I have presented at meetings on programming topics, and sessions on Design Patterns at Microsoft Devcons. I have published articles in Foxpro Advisor and Foxtalk, and was the VFP Pro on Fawcette Publications website.

Design Patterns:
I'm a huge fan of Design Patterns. They have totally changed my approach to object-oriented development.

Tool Creation:
I love to create tools (particularly for developers). My current favorite tool is CodeSmith: it's a template-based generation product. It is amazing to say the least!! The latest version is killer!

So what can you expect from my blog? Tune in and see!

I like the many connotations of "Head-Slapping" moments in everyday life and programming: everything from the "How could I be so stupid!" to the "Eureka!" to the "Rattling my head around (banging head against wall)" to get a new idea out. I plan to share these types of moments and what I learned from them (with code samples!).

Knee-slapping will be the humor that I will try to interject into what I present here.

Join me, won't you?