Make this piece of code more fault tolerant

When there are duplicate resource manager with the same name, an
exception will be thrown.