I have finally fixed it - I just trashed everything and started over, and to be honest I am not 100% sure what fixed it in the end because I spent hours doing iterative changes to try and work out what was going on. Definitely something to do with the order of tasks in my script. I did come across this error once too:
"Internal error: Exception of type 'System.Exception' was thrown." (otherwise the same as the original error - minus the 186 bytes part). Again this is a file that is recompiled as part of the update process, but I just thought I would post it in case you felt the need to improve the error message in a future build (but I have solved this too; same root cause as my original issue).
Speed of iteration here was pretty slow, it would be really useful if we could get either a way to remove updates from the .wyp file (as you or Wyatt mentioned to me before, we don't want to remove updates because that may leave users with unsupported versions, but in this case such a feature would have been a huge tmesaver for me). If we can't get this, then the ability to "replace" via the command line, rather than just "add" would have helped me too (because adding the same version from xml just gives an error if that build already exists, but doesn't seem to add any new files that are present). Failing that the ability to just create a new .wyp file from scratch via the command line would have done the same job for me.
Thanks for the help