Currently when I call GetWorkspace
I get ItemNotMappedException
exception, but when I iterate over workspaces manually I can get my code working. T
The VersionControlServer.GetWorkspace
method searches all known workspaces on the current computer to identify a workspace that has explicitly or implicitly mapped the provided local path. If no workspace is found, this method throws an ItemNotMappedException.
Try to call to Workstation.EnsureUpdateWorkspaceInfoCache in your code to force update the workspace information cache:
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("<your-tfs-uri-here>"));
VersionControlServer tfServer = tpc.GetService<VersionControlServer>();
Workstation.Current.EnsureUpdateWorkspaceInfoCache(tfServer, tfServer.AuthorizedUser);
Have a look at this similar question: Microsoft.TeamFoundation.VersionControl.Client.ItemNotMappedException even when the workspace exists and has a mapping