How to fix the Error 'was not found in hastack'

It's the validator for array elements in the Form and it has default in_array validator.
We can remove that validation using setRegisterInArrayValidator to false
   Ex : $userRoles->setRegisterInArrayValidator(false);