Added check in IR builder that the resource to be built is an AstNamespace before casting.