This looks wrong for me. If null causes a problem it shouldn't be ?int but it should be int. ?int means that it allows any int or null as input.

Can you give an example of code that trigger the error that you are getting?