Fix issue #794. Better errormessage on duplicate mref.