[Solved] TF31001: Cannot connect to Team Foundation Server

less than 1 minute read

Error

TF31001: Cannot connect to Team Foundation Server at .visualstudio.com.
The server returned the following error: Key not valid for use in specified state

Root cause

Expired token due to change in Windows credentials (Active Directory for Enterprise hosted TFS and Live credentials for Visual Studio Online)

Solution

Team Foundation Server when using Visual Studio 2013 stores token based on Windows credentials (Active Directory / Live credentials) in Windows Registry.  For example, I’m connected to 2 Visual Studio Online repositories, so you can see 2 keys in VssApp

image

Now when you change the credentials, in most cases this error will not come as Visual Studio will try to re-authenticate you and update the token.  However in case of any failures, you may get the error TF31001.

To resolve this,

  • Close all instances of Visual Studio
  • Run Task Manager and find out all TFS services.  Click on End Process Tree to shut down all the services
  • Delete just the TokenStorage folder:

    HKEY_CURRENT_USER\Software\Microsoft\VSCommon\12.0\ClientServices\TokenStorage

  • Restart Visual Studio and retry

Updated: