add fallback to reinterpret_cast if dynamic_cast fail and improve error messages
add fallback to reinterpret_cast if dynamic_cast fail