Core: fix endless recursion protection (#487).

The type loader's endless recursion protection doesn't throw a bogus "Endless recursion" exception when repeatedly tried to load a type with an invalid URI.

Thanks to MK for revealing this issue.

Close ticket 487.
Merge branch 'master' into edit-conflict