Fix dynamic_cast problem

fixes #7586