Why is this making an error?

Can you show us the code where you’re doing that? Just in case you missed something little that could throw the whole thing?