Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS API: GetLocalWorkspaceInfo always returns null

Tags:

c#

tfs-sdk

On one of my machines, I get a return value of null from any GetLocalWorkspaceInfo call. I have isolated to problem to where it even fails for this simple program:

namespace WorkstationTest {     using Microsoft.TeamFoundation.VersionControl.Client;      class Program     {         static void Main()         {             string workspaceLocalPath = @"C:\Dev";             var info = Workstation.Current                           .GetLocalWorkspaceInfo(workspaceLocalPath);              // info is always null here         }     } } 

What I have already checked:

  • The exact same code works on my other machine the way it should.

  • I have verified that I have a workspace at C:\Dev

    Workspace Screenshot

  • I have created a new workspace and in a different directory and changed the workspaceLocalPath variable in the code to match.

  • I have consulted the documentation which states that the return value will be null if the path is not in a workspace. From the above image, the path should be in a workspace.

Yet, everything seems to suggest this should work. Is there anything I could be missing?

like image 586
Nick Freeman Avatar asked Apr 11 '13 18:04

Nick Freeman


1 Answers

After migrating from TFS2013 to TFS2017 in the company I work for I had the same problem with Workstation.Current.GetLocalWorkspaceInfo.

What worked for me is a call to Workstation.EnsureUpdateWorkspaceInfoCache:

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<your-tfs-uri-here>")); VersionControlServer tfServer = tpc.GetService<VersionControlServer>(); Workstation.Current.EnsureUpdateWorkspaceInfoCache(tfServer, tfServer.AuthorizedUser); 

I added the above code lines to the constructor of my TFS proxy class that uses GetLocalWorkspaceInfo.

like image 149
Valvestino Avatar answered Sep 21 '22 09:09

Valvestino