Fix for #4727

Check if parameter is scalar before cast to string
If not throw InvalidArgumentException
Fix for #4727