I'm not sure if you are using these codes in a usercontrol object, but i think you do.
In UserControl object use UserControl_Initialize instead of Form_Load. In your code, Form_Load is not initialized so
ComPort remains 0 as it is declared as an integer. If you replace Form_Load as UserControl_Initialize the error disappears. I tried and it worked.
I hope, i didn't misunderstood.