Return error when method cache key generation fails. Closes #2089.Closes #2065