Currently when I call GetWorkspace
I get ItemNotMappedException
exception, but when I iterate over workspaces manually I can get my code working. This is so bizarre that I am wondering if I should call some refresh or something before I call GetWorkspace
?
Here is my code:
Workspace active = null;
using (var tfs = new TfsTeamProjectCollection(uri))
{
tfs.EnsureAuthenticated();
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
// displaying info and manually finding desired workspace
foreach (var ws in vcs.QueryWorkspaces(null, vcs.AuthorizedUser, Environment.MachineName))
{
Console.WriteLine(ws.Name);
foreach (var f in ws.Folders)
{
Console.WriteLine($" {f.LocalItem}");
if (f.LocalItem == map_path)
active = ws;
}
}
// at this point workspace is found and I can work with it
// but this will crash
Workspace workspace = vcs.GetWorkspace(map_path);
}
I use VS2015 and the library for TFS is fetched from NuGet repo. It is "Microsoft.TeamFoundationServer.ExtendedClient" version "15.112.1".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With