JBAcademyI’d like to thank the Academy… No, I haven’t won best-supporting actor for my portrayal of a mild-mannered .NET developer in some smash blockbuster. (At least not yet.) I’ve been accepted as a member of the JetBrains Academy. What is it all about? The Academy’s mission statement says it best:

The JetBrains Development Academy fosters a community of experts and evangelists to champion best development practices and promote software innovation worldwide. The Academy serves as a connection point for developers who strive to adopt top methodologies and use JetBrains products to help them achieve that goal.

You can find my Academy profile here. (No, I didn’t write it, though I am flattered.) The profile fits with the general tone of the Academy, as can be seen by reading the profiles of my good friends, Donald Belcham and JP Boodhoo. I wish I could be “as mellow, smooth, and intoxicating as [Donald’s] favorite single malt scotch”.

The next episode of Becoming a Jedi is now live and covers code cleanup. Specifically I look at quick fixes, context actions, safe delete, and reformat code. You can find it here:

Streaming: Becoming a Jedi – Part 2: Code Cleanup (requires Silverlight 1.0 or higher)*

Download: Becoming a Jedi – Part 2: Code Cleanup (via Live SkyDrive)

Enjoy!

Thanks to everyone for coming out to my presentation last week on new C# 3.0 features and what we can learn from other languages. You can download the slidedeck and demos here.

We’ve had a backlog of shows in the hopper waiting to be produced. Three episodes in one smash hit release, all available in MP3 format. On Episode 16, John and I try videocasting via ooVoo. Watch the talking heads and let us know if you like the new format or whether we should stick to audio only. (Assuming we keep the videocast format, we’ll produce both MP3 audio only as well as Silverlight video.)

Plumbers at Work – Episode 14 – Do You Have Change for a Ningy?

Bil and James are back for another half an hour of fun. Play MP3 audio.

  • Microsoft offers full versions of its development tools to students for free
  • Google Apps
  • Languages – Python, Ruby, Boo, F#, C#
  • ALT.NET Seattle Retrospective
  • NHibernate 2.0 Alpha released
  • Stackoverflow.com by Jeff Atwood and Joel Spolsky

Plumbers at Work – Episode 15 – The Man from Betelgeuse

John and James hold down the proverbial fort. Play MP3 audio.

  • John becomes a father
  • Becoming a Jedi screencasts (http://tinyurl.com/6m9r8s)
  • Silverlight Streaming (http://streaming.live.com)
  • DevTeach Toronto
  • Dependency Injection and Inversion of Control
  • Persistence and Infrastructure Ignorance
  • Microsoft and the Yahoo! bid
  • ALT.NET Open Space Canada
  • Bahamas .NET User Group
  • Silverlight 2.0 and Testing
  • The Twitter phenomenon
  • What are Don Box and his team really working on?

Plumbers at Work – Episode 16 – Oh No, Not Again

John and James try out ooVoo for videocasting. Play Silverlight video. Play MP3 audio only.

N.B. Don’t adjust your sets. John’s audio drops out for a few seconds near the beginning. There was no way to recover it unfortunately.

I’ve received a lot of great feedback on Becoming a Jedi and was planning on having the next episode done already. Unfortunately lightning struck twice. While fighting a horrid sore throat -likely the same illness that had Roy Osherove missing two of his three DevTeach presentations – my motherboard on my main dev box died a horrible BSOD death and corrupted my RAID array during its death throes. I’m picking up new hardware tomorrow and rebuilding the RAID array from a recent backup. Fingers crossed, I should be back in business and recording later this week, which would mean a new episode sometime next week. Thanks to everyone for your patience.

<message type=”aside”>

I cannot stress enough the value of a good backup plan. My main workstation stores everything on a RAID 0+1 array. I have essential data (client documents, family photos, corporate information) replicated between multiple computers via FolderShare. Any development or writing is stored in a Subversion repository – public or private depending on the work. Each computer is backed up using Vista’s Backup, which is far superior to Windows Backup in previous versions. Those backups include more files than is replicated via FolderShare. (FolderShare limits you to 10,000 files per library, which isn’t enough if you’ve got a few Subversion working copies kicking around in there.)

Now why do you need a good replication and backup strategy if you’re storing your information on a RAID 0+1 array? You can rebuild the array if a drive fails. Aren’t the replication and backups redundant? For those who skipped the beginning of this blog post, you need backups just in case your motherboard dies a horrible death and corrupts your RAID array. Or you realize that you accidentally deleted an important file a few days ago and in the meantime you’ve emptied the Recycle Bin and run a defrag. RAID arrays – while fantastic for protecting you from drive failures (RAID 1 or 5), or increasing performance (RAID 0), or both (RAID 0+1) – still do exactly what you – or the operating system – tell them to do. If the operating system crashes horribly and while doing so, sends the command to format c:, guess what’s going to happen?

So do yourself a favour and make sure your backups are in order. You never know when you’re going to need them next…

</message>

I’ll be one of the speakers at the Calgary .NET User Group this Thursday. First up is Daryl Rasmussem…

Building ASP.NET/AJAX with Visual Studio 2008 by Daryl Rasmussem

AJAX is now built into ASP.NET with Visual Studio 2008 – and because there’s no separate download to install, the fully integrated nature of AJAX gives you better separation of the code from the design, and the generated Javascript and HTML is cross browser compatible, including support for both FireFox and Opera.

In this presentation, we will use a real world development scenario to explore the following AJAX techniques in Visual Studio 2008:

· Partial Page Rendering and the use of Update Panels

· Using the UpdateProgress control

· Using Control Extenders from the AJAX Toolkit

· Creating a new Extender Control

· Working with web services – from both server and client side code

To C# 3.0… and Beyond by James Kovacs

C# 3.0 introduces lambda expressions, extension methods, automatic properties, and a host of other features. We will look at where C# is today, where it is going tomorrow, and what ideas we can borrow from languages like F# and Ruby to improve our C# code. Plus find out the real reason for the new “var” keyword.

Date/time: Thursday, May 29, 2008 from 5-8pm

Location: Nexen Conference Centre (801 – 7th Avenue SW, Calgary)

Registration: Calgary .NET User Group Events Calendar (N.B. You must be logged in to see the registration link.)

Another DevTeach has come and gone. I had an awesome time. I enjoyed hanging out with old friends and meeting some new ones. I saw a lot of great sessions, but the best part, as always, is the hallway and bar conversations. (No, I still haven’t quite figured out Metastones, even after playing for hours.) I wanted to especially thank everyone involved in the agile track – both presenters and attendees. I have received a lot of positive feedback on the track. Given that I organized the track, I am immensely pleased with its success.

You can download my slides and demos from here or the DevTeach site.

Achieving Persistence Ignorance with NHibernate (2.6 MB)

Taming Software Dependencies with DI and IoC (20.9 MB)

I have started keeping my latest presentations online in Google Code’s Subversion repository.

svn checkout http://jameskovacs.googlecode.com/svn/Presentations/

Take a look in the tags to get the slide deck and demos for a particular event. For example, you’ll find tags/DevTeachToronto2008 contains the version from – surprise, surprise – DevTeach Toronto 2008. If you have any questions or comments on slides, demos, or techniques, please don’t hesitate to email me.

DevTeach is returning to Montreal on December 1 to 5, 2008. I’ll be the Agile Track Tech Chair again. Jean-Rene will be putting out a call for sessions in the near future and you should find the announcement here. If you are interested in speaking in the Agile Track, feel free to email me. If you attended any sessions in the Agile Track and have suggestions for things that you’d like to see again or suggestions for improvement, email me!

…a ReSharper Jedi, that is. I am making no claims about my own ReSharper Jedi abilities. JP and Oren are known ReSharper Jedi Masters. I feel more like Luke Skywalker when he first landed on Dagobah in comparison. Back to the point of this post…

Many developers don’t see the value of JetBrains’ ReSharper until they’ve seen it in action. So I’m putting together this screencast series to show off my favourite ReSharper features. My goal is to keep each screencast to 5 to 10 minutes and focus on a related set of capabilities. In the first episode, I look at ReSharper’s Code Browsing – CTRL-N, CTRL-B, CTRL-ALT-B, ALT-F7, and related.

Streaming: Becoming a Jedi – Part 1: Code Browsing (requires Silverlight 1.0 or higher)*

Download: Becoming a Jedi – Part 1: Code Browsing (via Live SkyDrive)

Before someone makes a snarky comment about my coding speed, I’m intentionally taking the time to explain the features. That and I’m not as adept as some at coding and talking at the same time. Hopefully I’ll improve with practice as this screencast series progresses. Any constructive feedback on the content or presentation style is appreciated. Enjoy!

* I am encoding the series using Silverlight 1.0 for two reasons:

  1. In my tests with Camtasia, the Silverlight version scaled better than the Flash version. Text in Visual Studio remained clearer as the video was resized. The original recording is at 1024×768, but is still legible when scaled to 640×480 or smaller.
  2. I can host the content on Silverlight Streaming for free. When you sign up for an account, you get 10 GB of storage and 5 TB of bandwidth per month. The videos are distributed by Microsoft’s content delivery network and streamed from a server close to the viewer. As an author you simply upload your videos to Silverlight Streaming and Microsoft does the rest. I also don’t run the risk of blowing the bandwidth allotment at my hosting provider and incurring charges for bandwidth overages.

DevTeach is happening May 12-16, 2008, this time in Toronto, Canada. DevTeach is a fantastic conference and that’s not because I’m speaking there or organizing the Agile Track – though those are good reasons too. Just take a look at the line-up of internationally known speakers. Attendance is purposely capped in the hundreds to encourage speakers and attendees to meet, chat, dine, drink, and otherwise talk tech in a relaxed atmosphere. For those interested in agile development, the Agile Track has been expanded to 17 sessions over the full three days. There is also Party with Palermo, a keynote by Scott Hanselman (Microsoft), and .NET Rocks Panel Discussion with Scott Bellware, Ted Neward, and Oren Eini. If you’ve been itching to learn about TDD, Silverlight, WPF, SQL CLR, or other topics, there are one-day pre-/post-conference sessions available at reasonable prices. DevTeach is a fun and amazing learning experience. Hope to see you there! You can register here.

This morning I was getting ready to record a screencast about ReSharper 4 EAP. To make it easier for people to follow along, I launched Roy Osherove’s excellent utility, Keyboard Jedi. Rather than the expected result, this friendly dialog box greeted me:

image_thumb[2]

Living La Vida x64

My main development machine is running Vista x64. I’ve used KeyJedi frequently on my Vista x86 laptop and never had a problem. So I immediately suspected a 64-bit compatibility issue. KeyJedi is a .NET 2.0 application, which means that it will execute on the 64-bit CLR if available. (The 64-bit CLR was introduced with .NET 2.0. You don’t have to do anything special. If you install .NET 2.0 or higher on 64-bit Windows, the 64-bit CLR is installed automatically.) The 64-bit CLR uses a 64-bit JIT compiler, which produces x64 (or IA64)* machine code. This is why things like Paint.NET’s Gaussian Blur, which involves a lot of 64-bit arithmetic, run faster on 64-bit Windows. The MSIL is identical, but on 64-bit platforms, the JIT produces 64-bit optimized code. For example, a 64-bit ADD can be done in a single instruction on 64-bit hardware, but requires multiple instructions on 32-bit. (N.B. If you’re running 32-bit Windows on 64-bit hardware, there is no way to access the 64-bit capabilities of the chip as the OS thinks it’s running on a 32-bit chip.)

* x64 is the 64-bit enhanced, x86-compatible instruction set introduced by AMD. IA64 is used by Intel’s Itanium processors and is incompatible with x86. So you have to recompile the world to use IA64. Once Intel realized that not everyone on the planet was willing to recompile their programs, they introduced EMT64 for the Pentiums and Core chips. EMT64 is functionally identical to x64 from AMD.

WoW

So on Vista x64, KeyJedi is running on the 64-bit CLR. But that doesn’t explain why it fails. Most programs, like Paint.NET, just work. What is KeyJedi doing that is special and incompatible with 64-bit Windows? It is registering global system hooks to capture keyboard and mouse messages. Registering hooks and receiving messages involves Win32 calls, which are handled by Michael Kennedy’s Global System Hooks in .NET library. This library includes both managed (Kennedy.ManagedHooks.dll) and unmanaged (SystemHookCore.dll) code. SystemHookCore.dll makes 32-bit Win32 calls and receives 32-bit callbacks. You cannot make 32-bit Win32 calls directly to the 64-bit Windows kernel. You need a translation layer, which is the Windows-on-Windows or WoW layer.

The WoW layer marshals 32-bit Win32 calls to and from their 64-bit equivalent, translating data structures on the way in and out. This marvelous piece of magic is built into 64-bit Windows and allows most 32-bit programs to execute on 64-bit Windows without problem. The WoW layer sits below all 32-bit processes happily marshalling system calls back and forth. If you’re running in a 64-bit process, such as the 64-bit CLR host, there is no WoW layer beneath you. So you cannot load 32-bit DLL, such as SystemHookCore.dll. (This is also why 32-bit kernel-mode drivers don’t work on 64-bit Windows. There is no WoW layer in the kernel. It exists between user and kernel mode.)

Now we know the problem. The question is how to fix it. We could create a 64-bit version of SystemHookCore.dll, but that would involve a lot of spelunking and debugging of unmanaged C++ code. Not exactly how I want to spend my morning. The other option is to force KeyJedi to run on the 32-bit CLR even on 64-bit Windows. Then we would have the WoW layer beneath us and SystemHookCore.dll could merrily assume that it is running on 32-bit Windows while the WoW layer takes care of all the 32-bit to 64-bit Win32 marshalling. So how do we force a managed application to run on the 32-bit CLR…

Any CPU vs. x86

The easiest technique is to modify your project settings in Visual Studio. Just go to Project Properties… Build… Platform target and change it from Any CPU to x86.

image_thumb[9]

Now you might think, “Wait a second. I’m compiling to MSIL, which is processor independent.” Yes, you are, but when you select Any CPU (the default), your program will load on the 64-bit CLR if available. By selecting x86, you are forcing the program to run on the 32-bit CLR. Then just recompile your program and problem solved. Just one problem… Roy never released the source. (Yes, I’ve emailed Roy and asked him to do recompile with x86 as the target platform.)

No Source, No Problem

We don’t want to modify the application, just ask it to run on the 32-bit CLR. Turns out that the project settings above just twiddle the CORFLAGS inside the PE file header of the executable. The .NET Framework SDK ships with a program called corflags.exe for just this purpose:

image_thumb[12]

You’ll notice that 32BIT has a value of 0, which means Any CPU. We want to twiddle this to 1. One little problem. The assembly is signed. Twiddling even a single bit will invalidate the signature and the CLR loader will prevent the application from loading. If the assembly weren’t signed, you could just execute:

corflags KeyJedi.exe /32BIT+

ILDASM to the Rescue

Time to bring out the big guns. We’re going to disassemble KeyJedi.exe into MSIL. Hold onto your hats…

ildasm /all KeyJedi.exe /out=KeyJedi.il

This produces three files:

KeyJedi.il

KeyJedi.res

Osherove.KeyJedi.MainForm.resources

Time to hack some MSIL… Open KeyJedi.il in your text editor of choice and search for “.corflags”. Change the line to:

.corflags 0x0000000b    //  ILONLY 32BITREQUIRED

We can’t compile the code yet because we don’t have the private key that matches the public key embedded in the MSIL. Search for .publickey and delete it. (You could change it to your own public key generated with sn -k, but there’s no reason that we need to sign the assembly.) Now we can re-compile the MSIL using ilasm:

ilasm /res:KeyJedi.res KeyJedi.il /output:KeyJedi-x86.exe

If we execute KeyJedi-x86.exe, we get:

image_thumb[14]

Success!!! KeyJedi is now running on Vista x64.

Postscript

I’m not going to redistribute the recompiled binary because KeyJedi is Roy’s baby and the fix is really straightforward for him to make. Look to his blog for an update. My main purpose was to help people better understand 64-bit compatibility issues and some tricks that 64-bit Windows does so that, in most cases, you aren’t forced to recompile the world to run the programs you’ve come to depend on.