Are you an f5 addict?


I never run with the debugger attached. It's for finding out what is happening in the code and I don't need that 90% of the time when I am developing. It's only when something very odd happens that I hook up the debugger and dig into the depths of what is happening.

If you're addicted to F5 here are a few shortcuts that can make kicking the habit easier:

ctrl - shift - B : Build Everything
Compiles all projects in your solution that have changed

alt - B - U : Build Current Stack
Checks all the projects that are referenced by the current project and builds any that have changes or that reference a project that has changes, even if it's indirectly referenced.

alt - D - P - W enter : Attach debugger to w3wp (win2003+)
I use this a lot. It pulls up the "Attach to Process" dialog box and selects the fist thing in the list that starts with W. Since the list is sorted alphabetically, w3wp should be the first thing that starts with W. I usually tell people to think "Department of Public Works" to remember this. It's odd enough that it's easy to remember.
ctrl - F5 : Run without debugger
I use this mostly for small command line apps where I am just trying stuff out. It takes a few less seconds that having the debugger fire up and the code usually runs faster too.

author: Joe Sadowski | posted @ Sunday, March 16, 2008 4:33 PM | Feedback (0)

Interesting Compiler Quirk


Came across an interesting issue in the upgrading our code to c# 3.0 compiler today. Seems that this new compiler is a little too liberal in choosing the correct override of a method to call when enums are considered. You would think this would call Print(object) every time, but you would be wrong if you were using the C# 3.0 compiler. The first call would call Print(Y) even though there is no implicit conversion from int to our enum type Y.

enum X { Zero = 0, One = 1 }

enum Y { Zero = 0, One = 1 }

class Program
{
static void Main()
{
X zero = X.Zero;
Print((int)X.Zero);
Print((int)X.One);
Print((int)zero);
}

static void Print(object val)
{
System.Console.WriteLine("object: [{0}]", val);
}

static void Print(Y val)
{
System.Console.WriteLine("Y: [{0}]", val);
}

}

Compiled in C# 2.0 this prints:

object: [0]
object: [1]
object: [0]

Compiled in C# 3.0 this prints:

Y: [Zero]
object: [1]
object: [0]

So, it looks like the 3.0 compiler is throwing out the type information, but only if the underlying value of the enum is 0. If the value is something other than 0 it works as expected.

Lets take a look at the IL that is generated for our Main() method. Differences in bold.

2.0 IL

    L_0000: nop 
L_0001: ldc.i4.0
L_0002: stloc.0
L_0003: ldc.i4.0
L_0004: box int32
L_0009: call void Program::Print(object)
L_000e: nop
L_000f: ldc.i4.1
L_0010: box int32
L_0015: call void Program::Print(object)
L_001a: nop
L_001b: ldloc.0
L_001c: box int32
L_0021: call void Program::Print(object)
L_0026: nop
L_0027: ret

In this case the compiler gets this right and calls the only version of the method that makes sense for it.

3.0 IL

    L_0000: nop 
L_0001: ldc.i4.0
L_0002: stloc.0
L_0003: ldc.i4.0
L_0004: call void Program::Print(valuetype Y)
L_0009: nop
L_000a: ldc.i4.1
L_000b: box int32
L_0010: call void Program::Print(object)
L_0015: nop
L_0016: ldloc.0
L_0017: box int32
L_001c: call void Program::Print(object)
L_0021: nop
L_0022: ret

The main difference is that the compiler choose a different overload of the method to connect to and excluded the boxing that would allow the int to be passed as an object. Crazy stuff indeed.

author: Joe Sadowski | posted @ Friday, March 07, 2008 2:15 PM | Feedback (0)

After much work...


It's live!

author: Joe Sadowski | posted @ Sunday, November 11, 2007 12:12 PM | Feedback (0)

Internet Explorer goes into Quirks mode


I just spent the better part of a day trying to figure out why internet explorer (all versions) was reverting back to quirks mode on our site that had been working fine for weeks. I checked the usual places made sure the doctype was correct, even validated the page.

The doctype was perfect in the master page and everything looked fine. It's just that IE was clearly in quirks mode with a broken box model.

Well finally I happened to view source when it popped out at me that there was a comment above the doctype. Another developer had added some code to spit out debug info in a comment and had it hooked up in the code-behind. Something like this:

protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<!-- some comment -->");
}
This very much pissed IE off and caused the site to look like crap for a while.

The moral of the story is that any content should be rendered out during the render cycle in ASP.NET, even if it's a comment.

author: Joe Sadowski | posted @ Thursday, July 26, 2007 8:48 PM | Feedback (0)

Setting up Tortise SVN to be more VS Friendly


If you go under the settings tab you can specify a few wild card patterns that if files or folder names match any of these they will be ignored. If you drop this handy little piece of text in there "*.sou *.user bin obj" it will happily ignore most of the user specific Visual Studio junk files.

author: Joe Sadowski | posted @ Wednesday, June 27, 2007 12:32 PM | Feedback (0)

Internet Radio Day of Silence


Today many internet radio stations have gone silent in order to raise awareness of the impending bill to raise the royalty rates they need to pay. Check out the whole list of stations (pdf) and then head over to savenetradio.org to find out how you can help.

author: Joe Sadowski | posted @ Tuesday, June 26, 2007 9:57 AM | Feedback (0)