Wednesday, April 28, 2010


The garden is in full flush at the moment. The forsythia, daffs, plum blossom, primroses and tulips are just fading, while the Morello, Bramley and grape hyacinths are at their peak, and the bluebells, the Charles Ross and the lilac are just starting to burst their buds.

Cut and come again salad I planted in the greenhouse is starting to germinate, and today a batch of plants arrived, so as soon as I was back from work it was time to pot up sweet-peas and squash, to add leaf beet half the salad bed and the rest in the sunny herb bed, and put the tomato plants into grow-bags in the greenhouse. Between that, mowing the lawn and cooking dinner, I hardly stopped before it was getting dark, taking advantage of the last of this good run of almost summer weather before we get typical Bank Holiday cold and wet.

More project type tricks

The trick to make an F# project launch in the Visual Studio web server is a further application of a little trick I picked up a while back for Vs2008.

There I wanted to retrofit a Windows Workflow into an existing plain C# library project; which I started by building the workflow in a scratch project and copying the source across -- but then in the copy I lost the designer. So I looked at the project file and immediately I saw


Copying that into the otherwise vanilla C# project not only gave me the workflow designer, but also the workflow and activity items on the Add> menu. There is also a

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\Windows Workflow Foundation\v3.5\Workflow.Targets" />

but not copying that didn't seem to have any noticeable effect.

And, while I've not yet had cause to look, projects that bring in their own specialist types and designers will presumably have their own GUID values.



to an F# project gives the extra additions to the menus -- but without templates, and, more importantly partial class support -- you won't get much benefit from them, unlike with the web app launching.

Links for 28-Apr

StyleCop now open-sourced.

Mono's C# compiler-as-service -- now works in .net too!

IronRuby+Rails+Rack+IIS7 -- between this stack and the same for JRuby in Tomcat. cross platform web-apps have become fun!

No Bugs (e-book).

Unit testing FxCop rules.

Axum (Concurrency focussed language on .net) for VS2010

Snap! -- Aspect-oriented support library for .net

Double-dispatch as a code smell.


Iron* console for VS2010.

Tuesday, April 27, 2010

Launching an F# web application inside VS2010 as if it were C#

This is a follow-up to my comments on VS launcher for F# web apps, where I can put an example of the changed markup to the F# class library project to make it act like a web project and launch a browser with your Default.aspx page when you hit F5.

First, add the highlighted element to the topmost <PropertyGroup> clause in the .fsproj file thus:

where the first GUID is for web app, and the second for F# (as you can see by looking for the project in the solution file).

At the bottom of a C# web application .csproj you will find a block of code like

which you just want to copy and paste into your F# project following the

or equivalent line.

Now adding a trivial Default.aspx file containing

Welcome to ASP.NET on F#!

and the default web.config from a C# web project to the F# library, and running the project launches me that trivial web page into Firefox.

Actually getting F# to play nice with ASP.Net, I leave to those more versed in the latter.

Sunday, April 18, 2010

coverage.exe and instrumenting F# files

I observed yesterday that coverage.exe balked in PdbReader.GetSegmentsByMethod() when trying to instrument F#-derived assemblies.

By checking to see whether a new CodeSegment entry would provoke the exception by having an identical offset to a pre-existing one, and dumping both old and new to the console, I observed that at least one, and often both, had associated line number 0x00Feefee -- i.e. were compiler generated code with no source reference.

And in the method Executor.ProcessMethod(), which is the only place to call PdbReader.GetSegmentsByMethod(), entries with this line number are discarded before beginning to instrument the IL code -- so it would seem to make perfect sense to discard these CodeSegments before putting them in the dictionary. With that change, instrumentation completes cleanly.

Of course, having built coverage.exe with C#4 for .net 4, the helper DLL it built is compiled for .net 4 as well, which has stymied my first test attempt. Oh well, enough for today.

Getting coverage.exe (trunk) to work with nUnit and .net 4

Following up from yesterday, about an instrumenting coverage tool that I'd spotted on Googlecode (Apr 2015 : rescued to GitHub), what I needed to do to get the instrumenting coverage tool working under .net 3.5sp1 with nUnit 2.5.2 driving unit tests.

First, the command line looks like

[path to]\ClassLibrary1.dll [path to]\UnitTestClassLibrary1.dll /x coverage.xml /r /exe [tool path to]\nunit-console.exe [path to]\UnitTestClassLibrary1.dll

where the /r (backup and replace) flag is essential; so you need to work on a copy directory with your assemblies and their .pdb files.

Second, you need to make the following change to the coverage main program in Runner.cs, line 92 from

to be

The hard-coded relative path could be added as yet another argument instead; and I've not played around with the shadow-copy parameter.

But that at least -- with a totally trivial test set -- provided me with a clean run and non-empty coverage data.

So the next thing to do will be to port the whole lot to .net 4 and see what gives. Also, it will be worth trying the teamcity branch (faking NCover 1.x) to see whether the different AppDomain usage there means we don't have to resort to this trick.

Later: doing a rebuild of Coverage and the sample test under .net 4, with command line

[path to]\ClassLibrary1.dll [path to]\UnitTestClassLibrary1.dll /x coverage.xml /r /exe [tool path to nunint 2.5.4]\nunit-console.exe /framework=net-4.0.30319 [path to]\UnitTestClassLibrary1.dll

where the nunit-console.exe.config has been adjusted appropriately, I get

Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, lexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
   OS Version: Microsoft Windows NT 6.0.6002 Service Pack 2
  CLR Version: 2.0.50727.4200 ( Net 2.0 )

ProcessModel: Default    DomainUsage: Multiple
Execution Runtime: net-4.0.30319
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.

Server stack trace:
   at NUnit.Util.ProcessRunner.Load(TestPackage package)
   at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
   at NUnit.Util.RemoteTestAgent.AgentRunner.Load(TestPackage package)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Core.TestRunner.Load(TestPackage package)
   at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
   at NUnit.Util.ProcessRunner.Load(TestPackage package)
   at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
   at NUnit.ConsoleRunner.Runner.Main(String[] args)

However, if I do this as a two-stage operation

[path to]\ClassLibrary1.dll [path to]\UnitTestClassLibrary1.dll /x coverage.xml /r

to instrument the code and create a coverage file with zero visit counts throughout -- and then run nunit separately with rest of the command line

[tool path to nunint 2.5.4]\nunit-console.exe /framework=net-4.0.30319 [path to]\UnitTestClassLibrary1.dll

this then fills in the visit counts as expected.

We have code coverage for .net 4 -- at least under some conditions! And without having to rebuild any tools apart from coverage.exe!

Later yet (refrigerator logic) -- of course when working coverage in two passes, I don't need to do the fiddle to change the settings for the AppDomain. And I don't need to have coverage built in the same .net version as I want to run nUnit in, either. I can use the code as synched from Googlecode built under .net 3.5 even for .net 4 codebases; all I have to do now is fix the problems with running it over F# code.

Saturday, April 17, 2010

.Net 4.0, VS 2010, F#2 etc -- quick reactions

It's a pain that we don't yet have a F# for .net 4 compiler except in non-Express versions of VS2010; the transition from to for .net 3.5sp1 was completely painless for my infrastructure project, but the migration to building under .net 4 will be delayed.

As for my usual toolchain, nUnit works following the recipe here for tweaking app.config

        <requiredRuntime version="v4.0.30319" />
      <loadFromRemoteSources enabled="true" />

with command line flag /framework=net-4.0.30319; FxCop 1.36 with just the requiredRuntime clause added to the app.config.

If you don't set these when trying to analyze .net4 code, you get some pretty obvious runtime version mismatch diagnostics that tell you not to do that again.

And as expected, NCover 1.5.8 (free) loses the plot completely -- it can't connect to the changed profiling API.

I am currently investigating an alternative, which so far hasn't ruled itself out completely when running under .net 4 : it hasn't worked as-is, but I suspect that may be more due to F# than .net 4 (Unhandled Exception: System.ArgumentException: An item with the same key has already been added. in Coverage.Common.PdbReader.GetSegmentsByMethod) -- so I shall have to fork that and bugfix.

Later: This turns out to be in a method that sets up a dictionary of offset to code block (from line,column to to line,column), and is almost certainly a manifestation of the phantom code blocks I've seen before in F# -- which would mean simply having to identify and drop any blocks which are just NOPs.

Thursday, April 15, 2010

More predictable this time

Five years ago to the day I got a very strange result for suggested voting intention.

This time it's right on the money, at least for the top slot; the rest, not so much.

Take the Who Should You Vote For? UK General Election quiz

UK Independence
Liberal Democrat

You expected: UKIP

Your recommendation: UK Independence Party

Sunday, April 11, 2010

Anime — ソ•ラ•ノ•ヲ•ト (Sora No Woto, Sound of the skies)

An all original anime series, and the only one from the first quarter of this year I've even felt worth investigating.

It started with the teaser text "In a future land marred by a long lasting war, a quiet decline has begun. 15-year-old Kumika [sic] realises her dream to enlist in the army, and joins a unit of five in protecting a fortress. Together they create music that reverberates across the skies, over empty towns and empty seas." The musical theme plus the character designs caused a lot of people to liken it to cute girls comedy show K-ON!, and suggest synopses like

Episode 1: Kanata enlist in the Military
Episode 2: Kanata gets her first weapon
Episode 3: Kanata fails her army obstacle course and the gang gives 
           special lessons to help her pass.
Episode 4: Summer Vacation outside the fortress
Episode 5: /k/-ON gang lacks an officer in their fortress so they go 
           back to HQ to get one
Episode 6: Army Parade
Episode 7: Christmas at the fortress
Episode 8: Army Recruitment Drive
Episode 9: New moe soldier got recruited into the fortress
Episode 10: Summer Vacation outside the fortress. AGAIN!
Episode 11: Kanata's weapon is rusted, so the gang goes back to HQ to 
            maintain her weapon
Episode 12: Army Parade. AGAIN
Episode 13: Winter break. 

Then a preview came out, showing vaguely Spanish architecture and melancholy music, and it seemed that this was actually going to be more YKK meets Haibane Renmei than K-ON!, and intriguing enough to follow up.

Yes, Kanata Sorami, to whom we are first introduced, seems the usual ditzy anime high-schooler, but we already have some enigmatic back story where as a young girl she met a soldier who played the trumpet, a meeting which inspired her to follow in the same path. And as she walks through the town from where she is dropped off, to the fortress where she is stationed, we are introduced to the legend of the town -- the annual water-sprinkling festival that commemorates when five maidens from the fortress, aided by a giant spider, sacrificed themselves to protect the town from a demon, the legend being told to a background of faux-Klimt art intercut with scenes around the town, the fortress and the surrounding area -- with the mention of the spider flashing to one of the other girls working on a something mechanical that we later learn is a spider tank.

By the next episode it's clear that this is going to be an eclectic series --

Japanese girls wearing German uniforms exploring a Japanese music school in a Spanish town full of French people in Switzerland, shooting South African owls with German rifles -- MAKES PERFECT SENSE.

and, in amongst some "cute girls doing cute things" episodes, slowly some details of this exhausted world are revealed; and always, in the background, the haunting sound of Amazing Grace, played on the trumpet.

Yes, there are a few things that make for double-takes -- they have walking tanks, but only the one fixed-line phone from HQ to the fortress, and signalling from tanks is done by bugle calls and not radio -- but ultimately, this show is more about mood than anything else. That is, up until the last minute where there's a pointless epilog that jars with the quite satisfying conclusion.

In all, a good series, that maybe didn't fulfil all its ambitions, but stood head and shoulders above the rest of the shows that made their début at the start of the year.

Anime — Letter Bee

An offbeat setting, this one : a world in perpetual night, save for an artificial sun; an Edwardian style setting, with occasional anachronisms like the one motorbike shown; D&D style wilderness between each settlement, inhabited by mechanical steam-punk style bugs (gaichuu), and the main traffic between towns are the Letter Bees (equally often referred to as such in English, as well as Tegami Bachi in Japanese. And there's a lot of crazy Engrish in the naming of places (Broccoli Forest, Breath Mint Pass,...).

The story opens with one Bee, Gauche Suede, finding a young boy, Lag Seeing, who has been marked with enough postage to take him to his aunt for fostering -- this serves to introduce us to the setting, the postmen Bees with the magic amber powered guns (the setting collectively being known as Amberground) that enable them to channel their energies into effective attacks against the gaichuu, and their companions, known as dingos; then timeskip and the boy now wants to follow in his rescuer's career.

On the way to his interview, he happens across a girl in similar circumstances to his own who has been abandoned with insufficient postage -- so to prove himself he undertakes the delivery, only to find she's being sent to a freak show; outcome, the half-monster girl he's named Niche (after where he found her) becomes his dingo.

With Lag, we find out more about this world; and we regularly get sentimental tales about the feelings bound into letters -- the whole series is really a paean to the old-fashioned snail-mail correspondence of yore -- especially as Lag's magical energies are just designed to evoke these sorts of echoes from anything they strike.

And there's a long running thread behind all of this about what happened to Gauche after he just went missing some point during the timeskip, the presence of rebels against the settled order of things, and what was going on when the artificial Sun went out for a few minutes the day Lag was born, and a government airship came crashing down? There's a second season planned, so no doubt we'll find out then.

Unusually, the secondary characters include a wheelchair-bound girl, Suzette, who is Gauche's younger sister and shares birth date with Lag. The question of how she navigates doorsteps as tall as the radius of her main wheels is finessed -- in fact there's a distinct lack of adaptations in her house.

One thing that struck me about this series was the background music -- not just Sub-Postmistress Aria playing Air on a G string (lower right); but all though, there was a good string-based orchestral sound track. OP and ED were J-pop, with, to my mind, the first pair better than the ones that took over half way through.

Anime — Miracle Train : Welcome to the Oedo Line

Japan's love of anthropomorphization strikes again -- at the start of 2009 it was soft drink cans, this time it's train stations, in a man-service anime for girls.

I picked this one up as something for Karen to counter the girl-heavy bias of the normal selection of shows, but quite enjoyed it. It is slight -- most of the episodes are of the form "Girl boards train; girl discovers it's occupied by half a dozen suave young men in uniform; girl freaks a bit, but eventually is coaxed into telling about her problems; the guys then let her talk the problem out, with a little bit of slapstick and sight-seeing in their vicinity; everyone happy." -- but never gets embarrassingly bad or stupid. The worst it gets are in the three episodes outside the usual problem-solving where it tries for a bit of profundity while doing the "Secret Origins of the Miracle Train" and never quite seems sure of the mood or genre it's aiming for. And along the way you'll learn more trainspotter trivia for one of the newer lines in the Tokyo underground.

Overall -- Surprisingly good for Japanese light comedy.