Detect file name/namespace mismatches with easy to understand error message

Before this, such issues could cause exceptions from tools.namespace
that were not easy to discover the reason for.