I am trying to post an answer to my own question, but I am getting an error message when I try to submit it.
The error message is:
An error occurred submitting the answer., which is not a very helpful message.
In the meanwhile I've posted the most relevant bits of the answer as comments against the question, but I would like to post the full answer if possible.
Does anyone have any idea what the problem is?