Hi Mark
I had a very similar problem on my X350 and when I read the codes ( ICarsoft code reader ) it came up with Low Battery Voltage to Gearbox. I was advised on the forum to check the electrical plug on the gearbox for oil contamination. Apparently they are supposed to be changed when you change the oil, I think you need access to the inside of the gearbox to change the socket but not sure about that. Anyway I didn't see any oil contamination but I gave it all a clean up and touch wood it hasn't come back. I wonder if a failing battery might cause the fault as well.
Good luck
Pete