There are some strange things going on:
Even though you do have a reference variable. Looks like you do it often, accessing data pins from non-exec branches. Unsafe, potentially catastrophic.
The cast is not to blame here. But you can use an interface instead. I’d look for issues elsewhere. You did not answer about log warning / errors.