Fix attempted string cast of classes that cannot be cast to string