Cannot add new build templates or create team projects on TFS 2010 because of error ‘The File Exists’

The following tale from the support lines comes to us today from Premal Ghelashah.

Recently I was working on an issue where we were facing problems registering new build templates. The error message said that “The File exists”. We were facing this issue while adding templates by any name.

 

We were also facing issues creating new team project:

 

 

The Application event log had the following entry:

TF53010: The following error has occurred in a Team Foundation component or extension:
Date (UTC): 13/08/2013 14:45:51
Machine: zzzzzz
Application Domain: /LM/W3SVC/8080/ROOT/tfs-1-130208782708232421
Assembly: Microsoft.TeamFoundation.Framework.Server, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; v2.0.50727
Service Host: 69ee1f98-86e8-48b3-9bb9-673d8c2bad5d (Eyetech Group Projects)
Process Details:
  Process Name: w3wp
  Process Id: 3836
  Thread Id: 1820
  Account name: xxxxx\yyyyy

Detailed Message: TF30065: An unhandled exception occurred.

Web Request Details
    Url: [method: POST]
    User Agent: Team Foundation (devenv.exe, 10.0.40219.371)
    Headers: Content-Length=544&Content-Type=application%2fsoap%2bxml%3b+charset%3dutf-8&Accept-Encoding=gzip&Accept-Language=en-GB&Expect=100-continue&Host=etg-softdev%3a8080&User-Agent=Team+Foundation+(devenv.exe%2c+10.0.40219.371)&X-TFS-Version=1.0.0.0&X-TFS-Session=0369dbf6-9778-4bd1-aff2-05ef65e30706&TF-Instance=0369dbf6-9778-4bd1-aff2-05ef65e30706&SOAPAction=http%3a%2f%2fschemas.microsoft.com%2fTeamFoundation%2f2005%2f06%2fBuild%2fBuildService%2f03%2fAddProcessTemplates
    Path: /tfs/_tfs_resources/Build/v3.0/BuildService.asmx
    Local Request: True
    Host Address: ::1
    User: xxxxx\yyyyyy[authentication type: NTLM]

Exception Message: The file exists.
 (type IOException)

Exception Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Path.InternalGetTempFileName(Boolean checkHost)
   at Microsoft.TeamFoundation.Build.Server.ProcessTemplate.UpdateCachedProcessParameters(TeamFoundationRequestContext requestContext, VersionSpec versionSpec)
   at Microsoft.TeamFoundation.Build.Server.TeamFoundationBuildService.AddProcessTemplates(TeamFoundationRequestContext requestContext, IList`1 processTemplates)
   at Microsoft.TeamFoundation.Build.Server.BuildWebService.AddProcessTemplates(ProcessTemplate[] processTemplates)

 

FIX: Clearing the content of the following cache folder location resolved issue with build and team project creation. Apparently the folders cannot handle more than 65k files and we start facing this issue.

C:\Users\<tfsservice account>\AppData\Local\Temp

As soon as we cleared this folder, issue got resolved!!