Use InvalidOperationException fixes #413