Browsing Posts published by james

Here are the code samples from some recent presentations…

Alberta Architect Forum 2007 – Creating Flexible Software

Austin .NET User Group – The NHibernate Mafia and the Persistent Ignorant Domain Model

Edmonton Code Camp 2007 – Building Applications Using ALT.NET

Thanks to everyone for attending the sessions, asking questions, and providing feedback.

The Virtual PC download of Visual Studio 2008 “Orcas” has been great. No install. No chance of corrupting your current Visual Studio 2005 install. It just works and allows you to play with the early bits in a virtual environment. That’s one of the things that virtualized environments excel at. The Virtual PC images were timebombed to prevent their use in perpetuity. Now for the bad news… Microsoft originally announced that the timebomb date was March 15, 2008. In actual fact, it is November 1, 2007. After that, you’ve got a few options as detailed on Jeff Beehler’s blog post:

  • The VPC will reboot every 2 hours due to the Windows license being expired. Move your data somewhere else or make sure your demos are less than 2 hours.
  • Upgrade the Windows Server 2003 guest OS to use a non-trial license, such as from a MSDN Subscription. (Details in Jeff’s article above.)

None of these situations is ideal, especially for those without MSDN Subscriptions. Hopefully we’ll get the next Visual Studio 2008 beta in the near future.

I’ve been getting a lot of questions regarding VstsUnit for ReSharper 3.0. I’ve got good news and bad news.

First the bad news… I’ve been working on it off and on, though it’s offering some significant challenges. The object model is completely different and tests are executed in a dedicated test runner that ReSharper spins up. So test exploration is working, but test running is failing mysteriously without a good way to debug. The problem… I haven’t been able to connect to the transient process with a debugger – even with Debugger.Break(); in the test runner code.

Second piece of bad news… I’m trying to wrap my head around the new test running model in ReSharper. As far as I understand the new API, you get a call per test to run rather than the complete list. I’m not sure if this is going to be workable at all with VstsUnit due to unnecessary limitations imposed by Microsoft. The entire VstsUnit testing API is marked internal with [InternalsVisibleTo(MicrosoftPublicKey)]. So the only way to run the tests is through mstest.exe.

Third piece of bad news… After much struggling, VstsUnit doesn’t work for me for a whole variety of reasons. NUnit and MbUnit are just frictionless by comparison. When I absolutely must run VstsUnit (or NUnit/MbUnit), I’m using Jamie Cansdale’s TestDriven.NET. Not as pretty as the ReSharper Unit Test Explorer, but much more functional. Highly recommended.

The good news… For those of you who wish to continue using ReSharper’s Unit Test Explorer, I’ve released the source code on Google Code for both the ReSharper 2.5 and 3.0 versions. You can find it under vstsunit-resharper. If you have time and interest to work on this project, please drop me an email. I’m accepting patches… Open-mouthed I’m also releasing the code under The BSD License, which means that if JetBrains wants to grab the code and incorporate it directly into ReSharper, they are more than welcome to it!

N.B. Due to redistribution restrictions, I cannot place the required Visual Studio and ReSharper DLLs into the Subversion repository. You will need to copy the files into lib\ReSharper and lib\VisualStudio. See the Readme.txt files in these directories for more information.

Did you know that you can get Visual Studio Intellisense support when editing NHibernate’s configuration and mapping files?* Simply drop nhibernate-configuration.xsd and nhibernate-mapping.xsd from the NHibernate zip file into:

C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas

or

C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas

Once you’ve got the XML Schemas in the right location, you should see something like this when editing NHibernate configuration and mapping files…

NHibernateIntellisense

(The little light bulb is ReSharper 3.0 suggesting a Quick Fix to split the empty XML tag into start and end tags.)

* This XML Intellisense trick works for any XML Schema (XSD) file.

N.B. Dropping your XML Schema files in the similarly named C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\schemas\xml does absolutely nothing!

I created a few simple ReSharper templates to make working with NHibernate and Castle ActiveRecord easier. They currently default to SQL Server 2005 because that’s what I do most of my work against. Feel free to customize to your heart’s content.

You can grab them from here. Simply import the templates into ReSharper via ReSharper… Options… Templates… Live (or File) Templates… User Templates… Import Templates from File… You’ll want to add the file templates to your Quick access list.

The first file template is hibernate.cfg.xml. (N.B. ReSharper will try to name it hibernate.cfg1 and add the xml extension. Delete the “1” and hit enter.) The template will prompt you for the database server, database name, and mapping assembly.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="hibernate.connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="hibernate.connection.connection_string">Data Source=localhost;Initial Catalog=DATABASE;Integrated Security=True</property>
    <property name="hibernate.dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="hibernate.use_outer_join">true</property>
    <property name="hibernate.show_sql">false</property>
    <property name="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <mapping assembly="SimpleConfiguration"/>
  </session-factory>
</hibernate-configuration>

The second file template is <Class>.hbm.xml. You will want to rename it <Class>.hbm as ReSharper will add the xml extension for you. The template will prompt you for the class name and primary key name. You’ll also want to modify the PK generator. You’ll note that default-access is “field.pascalcase-m-underscore”, which means that if you map a property called “Name”, NHibernate will access it by the corresponding field name, “m_Name”. Change your default-access to whichever naming convention you prefer. (See property access and naming strategies in the NHibernate documentation.)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="SimpleConfiguration"
                   assembly="SimpleConfiguration"
                   default-access="field.pascalcase-m-underscore"
                   default-lazy="false"
                   default-cascade="none" >
  <class name="CLASS">
    <id name="PRIMARYKEY">
      <generator class="assigned" />
    </id>
  </class>
</hibernate-mapping>

Lastly we have the Live template for Castle ActiveRecord configuration. You can insert this into app.config or web.config. Simple position your cursor inside <configuration> and type arconfig<TAB>. If you already have other configuration sections, you’ll have to merge the activerecord section with the others.

<configSections>
    <section name="activerecord"
             type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
</configSections>
 
<activerecord>
  <config>
    <add key="hibernate.connection.driver_class" 
         value="NHibernate.Driver.SqlClientDriver" />
    <add key="hibernate.dialect"                 
         value="NHibernate.Dialect.MsSql2005Dialect" />
    <add key="hibernate.connection.provider"     
         value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.connection.connection_string" 
         value="Data Source=DBSERVER;Initial Catalog=DATABASE;Integrated Security=SSPI" />
  </config>      
</activerecord>

Enjoy!

The ALT.NET Open Space Conference in Austin has come to a close. It was a fantastic experience. I had an opportunity to connect with many people whose books I have read and tools I use. Thanks to everyone who came for sharing their time and knowledge. Given that I’m used to wearing the presenter hat, it was a refreshing change to attend a conference where the purpose was to discuss and question our core tenets. Which brings me to…

What is ALT.NET? This continues to be a hotly debated topic – before, during, and after the conference. My own take… ALT.NET is about considering alternatives, it is not about being alternative. It is about taking the best frameworks and tools from Microsoft, third-parties, and the open source community to build an application that is maintainable. It is not about being anti-Microsoft. Scott Hanselman suggested that Pragmatic.NET might have been a better name. I would tend to agree. At heart, everyone there was a pragmatic developer. (If you have not read The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas, you really should.) It’s about thinking outside the Microsoft MSDN canon when building software.

What I find truly amusing is that, as far as I can tell, Microsoft has not attempted to create a canon. The collective knowledge has been created by regular people like us and people are fallible. Ideas that seem good at first may not stand the test of time. (DataSets/DataAdapters are a great example of an idea that in hindsight isn’t such a great one.) Microsoft is very open to better ways of developing software, as evidenced by the fact that many Microsoft employees attended. What many perceive as hostility to the community is more often disconnection from the community. But the honest truth is that they want to engage with us. I had great conversations with Simon Guest (Architecture Strategy Team), Howard Dierking (Editor in Chief of MSDN Magazine), Scott Guthrie (DevDiv), Peter Provost (P&P Team) Scott Hanselman (newest member of the Borg), and many other ‘softies about the values of the ALT.NET community and how Microsoft technologies support or hinder the development of maintainable software. (My intended purpose isn’t name dropping, but to show you, dear reader, that it’s the movers-and-shakers in Microsoft who are interested in providing a better development experience. These are the people who shape the platform and its documentation.)

Some people, who didn’t attend, have claimed that the conference was cliquey; that it was a venue for like-minded developers to say, “I do TDD.” and another developer to say, “Hey, cool. I do TDD too. You’re awesome.” On the contrary, the purpose was to foster better understanding of new techniques, such as BDD, specifications, domain-specific languages, FIT, etc. The conversations all started with a mutual understanding of what we were trying to achieve – more maintainable software supported by appropriate test artifacts.

For example, there was a lot of discussion around specification languages (like NBehave) were valuable compared with a written story on an index card. A written story is approachable by a non-technical business stakeholder and can elicit a discussion that might not otherwise happen. A specification written in C# (or Ruby) sitting in a source control system is not approachable by the non-technical business stakeholder. The answer is it depends on the individuals involved in the project. Each technique causes friction and your choice depends on which type of friction results in less project risk.

Another topic that has been widely reported is Scott Guthrie’s first public demonstration of the new ASP.NET MVC Framework. There were some pleasant surprises, including:

  • Microsoft’s commitment to testability. Controllers interact with the ASP.NET pipeline through IHttpRequest/Response rather than HttpRequest/Response. That little “I” allows us to mock out the dependency on the HTTP pipeline and run controller tests without all the ASP.NET hosting infrastructure. (ScottGu is looking to port those interfaces back into ASP.NET WebForms too.)
  • Microsoft will provide easy integration with a variety of other frameworks. For instance, if you want to mock a dependency, you can use Rhino Mocks, NMock, or TypeMock. If you want to use an inversion of control (IoC) container, Microsoft will allow you to bolt in Castle Windsor, Spring.NET, StructureMap, or ObjectBuilder. The team is even planning on providing templates for these open source frameworks. Microsoft is working with the community rather than trying to compete against it.
  • ScottGu’s team is not trying to wedge MVC into the existing WebForms model. If you use MVC, you are opting out of viewstate, postbacks, and the dreaded ASP.NET Page lifecycle. This is a brave move to make. WebForms will still work as it always has, but if you choose MVC, you will use a new set of controls specifically designed for the MVC model.
  • The bi-directional routing engine looks awesome. It allows for very flexible and human-readable URLs. The use of lambdas to create URLs was very cool.
  • The default view engine is ASP.NET. So you get all the design-time, CSS, and Intellisense support, but without the complex ASP.NET Page lifecycle, as noted above. You can easily create typed view data to communicate between your controller and view. (In MonoRail, the controller and view communicate via an untyped property bag. So you don’t get Intellisense and refactoring support.)

Overall, the design of ASP.NET MVC looks a lot like Castle MonoRail and has aspects of Ruby on Rails and Django sprinkled in. I’m looking forward to watching this technology develop. Jeremy Miller echoes my sentiments when he says, “I’m more excited about an upcoming Microsoft technology than anything else since moving from VB6 to .Net.” If you know Jeremy, he’s a hard developer to impress. So that says a lot!

There was so much more. I’ll try to put my thoughts around other discussions in the coming days as I mentally digest everything that was discussed. I’ll leave you with some personal highlights:

  • I enjoyed finally meeting Jamie Cansdale (TestDriven.NET) and hearing that he and Microsoft had come to an amicable agreement over TestDriven.NET.
  • It was great to meet Jay Flowers and thank him for all his great work on CIFactory. I even convinced him to implement an option in CIFactory to flip from using the command-line, CCNet.exe, to the Windows Service, CCNetService.exe.
  • Rock climbing Saturday night with Scott Hanselman, Russell Ball, and others was a blast. I didn’t feel like “a monkey with fly paper gloves”, but it was still a lot of fun. Maybe I’ll take it up as a hobby… 
  • Talking to Martin Fowler over dinner about the challenges in parallel computing. He said, “Concurrency is a lot like a white fluffy bunny…” at which point he leapt up and down wildly yelling, “with fangs and a mean streak a mile wide!!!” (Fans of Monty Python’s The Holy Grail will understand the reference. If you don’t, go rent the movie right now.)

You upload an Office 2007 file (pptx, xlsx, docx, etc.) to your IIS6 web server and someone tries to download it, but receives:

HTTP Error 404 – File or directory not found.

Internet Information Services (IIS)

The file is on the server. The URL is correct. You can even download ppt, doc, xls, zip, and other files from the same location. What’s up???

Out of the box, IIS6 only accepts requests for known MIME types. Since Office 2007 was released after Windows Server 2003 and IIS6, IIS6 knows nothing about the new MIME types. So you need to manually add them:

  1. Open Computer Management. (Right-click My Computer… Manage…)
  2. Right-click Internet Information Services (IIS) Management… Properties…
  3. Click MIME Types…
  4. Click New… and add the following:
Extension MIME Type
.xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx application/vnd.openxmlformats-officedocument.spreadsheetml.template
.potx application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptx application/vnd.openxmlformats-officedocument.presentationml.presentation
.sldx application/vnd.openxmlformats-officedocument.presentationml.slide
.docx application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx application/vnd.openxmlformats-officedocument.wordprocessingml.template
.xlam application/vnd.ms-excel.addin.macroEnabled.12
.xlsb application/vnd.ms-excel.sheet.binary.macroEnabled.12

N.B. These MIME types were added to IIS7 as noted in KB936496.

Scott Guthrie has announced that Microsoft will be releasing the source code and debug symbols (aka PDB files) for the .NET Framework assemblies when they release .NET Framework 3.5 later this year.* Initially this will include the .NET Base Class Libraries (System.IO, System.Collections, etc.), ASP.NET (System.Web), Windows Forms (System.Windows.Forms), ADO.NET (System.Data), XML (System.Xml), and WPF (System.Windows). Additional source code will be released in the coming months for WCF, WF, LINQ, and others. This is fantastic. Although Lutz Roeder’s Reflector allows you to view implementation, it is not produce full-fidelity source code as it has no way to infer comments, local variable names, or other details that get washed out by the compiler. Now we can finally debug directly into Microsoft’s code as well as our own when troubleshooting. Kudos to Scott and his entire team for taking this step to make the .NET platform even better.

* From what I can see, the release of source code and debug symbols is only for .NET Framework 3.5 and not for previous versions. This is still a huge step forward. Publisher web log

…for another year as an MVP. I just heard today that I was re-awarded as a MVP in Solutions Architecture for 2008. Another fun year of mischief, mayhem, and coding. You can always catch my latest misadventures here on my blog or get a summary version on my MVP profile. Thanks to my family and the community for your continued support and encouragement!

Having attended Harvard, I am very familiar with the friendly rivalry between Harvard and MIT. The MIT engineers are notorious for their pranks aka hacks, sometimes at the expense of Harvard. To celebrate the release of Halo 3, the famous bronze statue of John Harvard in Harvard Yard underwent an extreme makeover.

John Harvard Before:

John_Harvard,_statue_at_Harvard_University 

John Harvard After:

JohnHarvardMasterChief