TFS Test Agent cannot connect to Test Controller gives ‘No connection could be made because the target machine actively refused it 127.0.0.1:6910’

Whilst setting up a  TFS 2012 Standard Lab Environment for an upcoming demo I hit a problem. Initially my environment had worked fine, I could deploy to my server VM in the environment without error. However, after a reboot of the TFS server (which has the build and test controllers on it) and the single server VM in the environment, the test agent on the VM could not connect to the test controller on the TFS SERVER. The VM’s event log showed

Unable to connect to the controller on ‘tfsserver:6901′. The agent can connect to the controller but the controller cannot connect to the agent because of following reason: No connection could be made because the target machine actively refused it 127.0.0.1:6910. Make sure that the firewall on the test agent machine is not blocking the connection.

The key here was test controller was being told to call back to the test agent on 127.0.0.1 – which is obviously wrong being the loopback address.

So it seems the test agent was telling the test server the wrong IP address, not sure why it was resolving this address but I did find a workaround, on the test VM I edited 

‘C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\QTAgentService.exe.config’

and added the BindTo line with the correct address for the controller to call back to the agent

<appSettings>
     // other bits …
      <add key="BindTo" value="10.0.0.1"/>
</appSettings>

Once I restarted the test agent it connected to the controller and I could run my builds.

For more details on this config file see http://msdn.microsoft.com/en-us/library/ff934571.aspx