Changed validation to ensure it's a valid resource

It might happen the resource is invalid in case you are caching your objects.