[mcs] Better check for invalid attribute targets. Fixes #17447