BM-Bloggers

The blogs of Black Marble staff

Addressing binding issues with with Ivonna 2.0.0 using <dependentAssembly> in web.config

I have been having some binding problems when trying to use Ivonna 2.0.0 against a version of Typemock Isolator other than the 5.3.0 build it was built to run against. This is a know issue, if your version of Ivonna and Typemock don’t match then you have to use .Net Binding redirection to get around the problem.

So to track down the exact problem I used the Fusion logger shipped with the .NET SDK (via fuslogvw.exe). This in itself has been an interesting experience. A few points are worth noting:

  • You cannot alter the settings (as to what it logs) from fuslogvw.exe unless you are running as administrator (because these a really just registry edits in HKLM\SOFTWARE\Microsoft\Fusion node). However you can use the viewer to view logs even if not an administrator as long as the registry entries are correct.
  • I could only get the Fusion log to work if I was running my ASP.NET application in Visual Studio 2008 running as administrator, if I was a standard user nothing was logged.
  • You have to remember to press refresh on fuslogvw.exe a lot. If you don’t you keep thinking that it is not working when it really is.

Anyway using the fusion logger I found I had two problem assemblies, not just the one I had expected. I had guessed I need to intercept the loading of the main Typemock assembly, but what the fusion logger showed me was I also needed to intercept the Typemock.Intergration assembly. Also I needed to reference the Typemock.Intergration assembly in my test project and make sure it was copied locally (something I had not needed to explicitly do when using Typemock 5.3.0 where it had found via I assume via the GAC)

Now it is important to remember that if using MSTEST and Ivonna you need to point the build directory for the Test Project to Web Application under test’s bin directory. This means that the .NET loader will check the web.config in the web application for any binding information, not just in the app.config in the test project as I had first assumed.

So all this means that I needed to add the following to my Web Application’s web.config and app.config

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="TypeMock.Integration"
publicKeyToken="3dae460033b8d8e2"
culture="neutral" />
<bindingRedirect oldVersion="5.3.0.0"
newVersion="5.3.1.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="TypeMock"
publicKeyToken="3dae460033b8d8e2"
culture="neutral" />
<bindingRedirect oldVersion="5.3.0.0"
newVersion="5.3.1.0"/>
</dependentAssembly>

</assemblyBinding>
</runtime>

Once this was done all my test loaded as expected

Updated 4th June 2009 – There is now 2.0.1 release of Ivonna that does support Isolator 5.3.1 so this binding is not required, but details are good as in the future there is bound to be another version mismatch

The setup story for TFS 2010

I have been looking at the various install and upgrade stories for the TFS 2010 Beta. I have to say they are very nice compared to the older TFS versions. You now have a SharePoint like model where you install the product then use a separate configuration tool to upgrade or setup the features required. There are plenty of places to verify your setting as you go along to greatly reducing the potential mistakes.

One side effect of this model is that it is vital to get all your prerequisites in place. The lack of these has been the cause of the only upgrade scenario I have tried that has failed. This was on a VPC I used for TFS 2008 demos. This VPC used a differencing VHD using the older 2004 format that had a 16Gb limit and this disk was virtual full. To upgrade to TFS 2010 I needed to upgrade SQL to 2008 and this in turn needed Visual Studio 2008 patched to SP1 which needed over 6Gb free space, which was never going to happen on that VHD. So my upgrade failed, but that said this is not a realistic scenario, who has servers with just 16Gb these days!

Configuring IIS Bindings to include host headers with https on Windows Server 2008 (for SharePoint)

NOTE: We use a wildcard SSL certificate which makes our life much easier when dealing with multiple hostnames. I have not tested this approach with multiple SSL certificates for specific sites.

We’ve been reconfiguring our SharePoint 2007 farm over the past couple of days and it’s now hosted on Windows Server 2008 and using NLB (network load balancing). The load balancer has been configured with a single public IP address and all our previous DNS CNAME registrations have been replaced with hostname A registrations pointing at the address. With our previous configuration we had multiple IP addresses on the server, one for each web application. Each IIS web site was then configured with a host header and ip address to allow for secure traffic over HTTPS.

With our new configuration, I didn’t want to specify an IP address on the web site. Handily, IIS 7 makes that scenario possible (and even relatively straightforward). The only snag is that you can’t configure the necessary bindings through the IIS Manager GUI. You can do it through an xml config file, however:

  1. Look in c:\windows\system32\inetsrv\config and edit the applicationHost.config file. Make sure you take a backup first!
  2. Find the <sites> section in the file. In there you will find a <site> element for each IIS web site. Each of those has a <bindings> element with each port/protocol binding listed. Our main site looked like this:
    <bindings>
    <binding protocol=”https” bindingInformation=”*:443:” />
    </bindings>

    and we changed it to look like this:
    <bindings>
    <binding protocol=”https” bindingInformation=”*:443:myhost.mydomain.com” />
    </bindings>
  3. Repeat for each web application. If you have more than one web application on the same IP address using either http or https you need to configure a host header or you’ll have problems.
  4. Execute an iisreset.

We now have all our content web applications, the SSP and the central administration web sites all running on a single IP address, many on the same port and using SSL.

As I said at the start of this post, we use a wildcard certificate which makes my initial IIS configuration easier. I haven’t tried multiple certificates, and I’m interested to know if that works or not.

Incoming Email with SharePoint on Windows Server 2008

I’ve been meaning to write this up for a while, simply because it’s not quite as straightforward as with Server 2005.

To configure incoming email on SharePoint when running on Server 2008 you’ll need to run through the following steps:

  1. Install the SMTP feature
    Open Server Manager. Click on Features in the left hand column then click add features in the right hand pane. Tick the SMTP Server check box and click install.
  2. Configure the SMTP Service in IIS Manager (version 7)
    Start Internet Information Services (IIS) Manager from Administration tools in the Start Menu. Once open, click the name of the web server to bring up the options in the centre panel. In the centre panel, right-click SMTP E-mail and select Open Feature from the menu.
    Click the option to ‘store e-mail in pickup directory’ and set the path to be c:\inetpub\mailroot\Drop (that’s the default).
  3. Configure the SMTP Service in ISS Manager (version 7)
    Start Internet Information Services (IIS) 6.0 Manager from Administration tools in the Start Menu. Expand the server to show the SMTP service. In the ‘domains’ section, add any email domain aliases you need in there. Configure the other SMTP service settings just like you did with Server 2005.

SharePoint Service Pack 2 Pains

I finally bit the bullet and decided to upgrade our SharePoint farm yesterday. I’d been holding off for a while because of time constraints and because of a known issue with Project Server, also part of our farm.

I took careful steps to increment the farm from the SP1+Infrastructure update all the way through each CU up until the service pack. That all worked fine. It was when I tried SP2 I hit problems.

The first issue was that once I’d installed the WSS patch, the Sp2 patch refused to install. Rebooting the server then caused chaos as all my services complained that the SharePoint DB was the wrong version (too old, because I hadn’t run the config wizard yet).

Andy and I spent a long time poking the server yesterday, and spent time building virtual machines to take over the farm as well. We finally knocked it on the head just shy of midnight and left the server in the state it was, trying to start the upgrade installer.

When I got in this morning, the upgrade had installed. I’m guessing that the problems we were seeing were related to services starting and needing time to fail, and we simply hadn’t given them enough time to fail (mind you, the paranoid disk integrity check took a while…)

Much happier, I started the upgrade wizard. Which promptly failed. The logs showed the following:

[WebApplicationSequence] [ERROR] [5/27/2009 7:48:09 AM]: Action 12.0.4.0 of Microsoft.SharePoint.Portal.Upgrade.WebApplicationSequence failed.
[WebApplicationSequence] [ERROR] [5/27/2009 7:48:09 AM]: Feature '20477d83-8bdb-414e-964b-080637f7d99b' is not installed in this farm, and can not be added to this scope.
[WebApplicationSequence] [ERROR] [5/27/2009 7:48:09 AM]:    at Microsoft.SharePoint.SPFeatureCollection.AddInternal(Guid featureId, SPFeaturePropertyCollection properties, Boolean force, Boolean fMarkOnly)
   at Microsoft.SharePoint.SPFeatureCollection.Add(Guid featureId, Boolean force)
   at Microsoft.SharePoint.Portal.Upgrade.ActivatePublisingTimerJobsWebAppFeature.Upgrade()
   at Microsoft.SharePoint.Upgrade.SPActionSequence.Upgrade()
[ActivatePublisingTimerJobsWebAppFeature] [12.0.4.0] [DEBUG] [5/27/2009 7:48:09 AM]: Begin Rollback()
[ActivatePublisingTimerJobsWebAppFeature] [12.0.4.0] [DEBUG] [5/27/2009 7:48:09 AM]: End Rollback()
[ActivatePublisingTimerJobsWebAppFeature] [12.0.4.0] [DEBUG] [5/27/2009 7:48:09 AM]: Begin Dispose()
[ActivatePublisingTimerJobsWebAppFeature] [12.0.4.0] [DEBUG] [5/27/2009 7:48:09 AM]: End Dispose()
[ActivatePublisingTimerJobsWebAppFeature] [12.0.4.0] [DEBUG] [5/27/2009 7:48:09 AM]: Elapsed time: 00:00:00.0312496.

A quick dig with our old friend google turned up a couple of similar posts from Jukka on Moss and MySharePointofView so I had a look at the 12 hive and to my surprise found that there was no folder for the PublishingTimerJobs feature. I copied it from one of the new servers, already patched to SP2 and ran the command:

stsadm –o installfeature –name PublishingTimerJobs

That succeeded. I then followed with the old favourite:

psconfig –cmd upgrade –inplace b2b –force

That upgrade has just completed. No project-related errors, just success, so I add my experience to the collective.

Creating a new Virtual PC using the Virtual Windows XP Base Disk

One of the most useful elements of the Virtual Windows XP feature in Windows 7 is that the VPC is easily replicated and you can have multiple virtual machines all publishing applications which run in their own sandboxes.

  1. Create a new Virtual Machine
  2. Create a Differencing Hard Disk from the Virtual Windows XP Base
  3. Start the VM and run through the setup wizard:
    1. Accept the Licence Agreement
      image
    2. Set the keyboard and locale to your needs
      image 
    3. Give the PC a name and administrator password
      image
    4. Set the time zone
      image
    5. Wait while it configures networking…
      image
    6. … and runs through the final steps, followed by a reboot.
      image
  4. Configure the VPC for updates and user accounts:
    1. On restart, choose an option for automatic updates
      image
    2. You should now be logged in as administrator
      image 
    3. Open up Computer Management and enable the ‘User’ account, then reset the account password to something you know.
      image
      image
    4. Enable Integration Features from the VPC Tools Menu
      image
    5. Set the login account to the user account you just enabled.
    6. Accept the logon message to disconnect Administrator
      image
  5. Configure the applications on the VPC:
    1. Once you’re logged on as User, create a new shortcut in c:\documents and settings\all users\start menu and wait a few minutes.
      image
      You should see your start menu update with the new application shortcut
      image
      Each virtual machine gets a folder in your start menu beneath Windows Virtual PC and the applications on each PC appear in there.
    2. Once you’ve finished configuring your applications, log off your session on the virtual PC (don’t close the PC or shut it down)
      image
    3. Then close the VPC down from the Action menu and choose Hibernate
      image

If you now start any of the applications that have appeared in your main computer’s Start menu, the VPC will fire up in the background and you application will appear on your desktop. This is a great way to create multiple VPCs with applications that might conflict with each other.

There is a catch, however. Windows Virtual PC requires hardware virtualisation support to work. In my opinion this is a mistake. Since the virtual machines use emulated hardware rather than accessing the machine hardware like Hyper-V VMs do, I can’t see the reasoning here. Virtual PC 2007 used the hardware virtualisation if it was available but didn’t force it on you, which was the correct approach. Lots of businesses will find this technology useful, but will discover that the majority of their computers won’t be able to use it. At that point, the solution may as well not exist, and I for one hope that Microsoft change their mind about hardware virtualisation support before Windows Virtual PC ships.

Everytime I have to use Typemock I need to ask does my code stinks?

Ok a bit sweeping but I think there is truth in this, if you have to resort to a mocking framework (such as Typemock the one I use) I think it is vital to ask ‘why am I using this tool?’ I think there are three possible answers:

  1. I have to mock some back box that is huge and messy that if I don’t mock it will mean any isolated testing is impossible e.g. SharePoint
  2. I have to mock a complex object, I could write it all by hand, but it is quicker to use an auto-mocking framework. Why do loads of typing when a tool can generate it for me? (the same argument as to why using Refactoring tools are good, they are faster than me typing and make less mistakes)
  3. My own code is badly designed and the only way to test it is to use a mocking framework to swap out functional units via ‘magic’ at runtime.

If the bit of code I am testing fails into either of the first two categories it is OK, but if it is in third I know must seriously consider some refactoring. Ok this is not always possible for technical or budgetary reasons, but I should at least consider it. Actually you could consider category 1 as a special case of category 3, a better testable design may be possible, but it is out of your control.

So given this I looked at the new Typemock feature with interest, the ability to fake out DateTime.Now. Something you have not been able to do in the past due to the DataTime classes deep location in the .NET framework. OK it is a really cool feature, but that is certainly not a good enough reason to use it. I have to ask if I need to mock this call out does my code stink?

Historically I would have defined an interface for a date services and used it to pass in a test or production implementation using dependency injection e.g.

public class MyApplication 
{
public MyApplication(IDateProvider dateProvider)
{
// so we use
DateTime date1 = dateProvider.GetCurrentDate();
// as opposed to
DateTime date2 = DateTime.Now
}
}

So in the new world with the new Typemock feature I have three options:

  1. Just call DateTime.Now in my code, because now I know I can use Typemock to intercept the call and return the value I want for test purposes
  2. Write my own date provider and use dependency injection to swap in different versions (or if I want to be really flexible use a IoC framework like Castle Windsor)
  3. Write my own date provider class with a static GetDate method, but not use dependency injection, just call the method directory wherever I would have called DateTime.Now and use Typemock to intercept calls to this static method in tests (the old way to get round the limitation that Typemock cannot mock classes from MSCORELIB

I think this bring me back full circle to my first question: does the fact I use the new feature of Typemock to mock out DateTime.Now mean my code stinks? Well after bit of thought I think it does. I would always favour putting in some design patterns to aid testing, so in this case some dependency injection would appear the best option. Like all services it would allow me to centralise all date functions in one place, so a good SOA pattern. With all my date service in one place I can make a sensible choice of how I want to mock it out, manual or via an auto mocking framework.

So in summary, in mocking, like in so many things in life, just because you can do it is no reason why you should do something in a polite society. If you can, it is better to address a code smell with good design as opposed to a clever tool.

Post Developer Day South West thoughts

DD-SW in Taunton seems to go well, a big thank you to Guy and the rest of the Bristol .NET user group for all their work getting this event up and running. Also it was nice to see new faces, it is certainly a good idea to get the DDD family events out to places beyond Reading, spreading the good works of the community across the country.

Thank you to those who attended my session on Scrum, I hope you all found it useful. You can find a virtually identical set the slides on the Black Marble web site and the actual stack I used will be up on the DD-SW site soon.

I actually managed to attend some sessions this time, as usual this just means more work as I invariably realise I have to spend some time on learning some new technologies This time it was MEF and jQuery, the latter  technology I have ignored too long. It was also great to see a truly mind bending session by Marc Gravell on Expression trees, we need to see more of these deep dive sessions a community events. I have never checked to see if is it that they are not proposed or that they are not voted for? Can it be true the community just wants level 200 general overviews?

Anyway another great day – a pointer to everyone that if you haven’t been to DDD event you really should.

Timeouts on Bitlocker to go

Since moving to Windows 7 I have encrypted all my USB pen drives and external USB disk drives with Bitlocker to go. This has been working great for me, I have noticed no performance problems and it give nice piece of mind. The only irritation is when you plug the encrypted drive into an XP or Vista PC you can’t read it, but this is meant to be being addressed.

However, I have seen one issue, this is that there seems to be a timeout if the bitlockered to go device is not accessed for a while (well over an hour is my guess, I have not timed it) it relocks itself and the password has to be re-entered. I can’t find any setting anywhere to control this timeout. I suppose the workaround is to set the bitlockered device to always automatically unlock on my PC, but I do like the security of having to enter the key manually.

The other possibility is that it is not a Bitlocker thing and it that my USB ports are resetting, and in effect reattaching the device. I suppose the effect is the same.

As my external USB pod contains mostly Virtual PC images in effect removing the underlying disk when they are running is a bit of a problem; but as long as you know it might happen you can live with it.

Update 28 May 09 – I now think it is my USB ports power saving mode, same net effect though