Fix problem with serializing dynamic ports

Part of #445