I'm facing issues accessing a TFS WorkItemStore via C# code when I'm using impersonation. The code that I'm using is as follows:
Uri tfsUri = new Uri("https://localtfsinstance/tfs);
NetworkCredential cred = new NetworkCredential("tfsusername", "tfspassword", "ADDomain");
BasicAuthCredential basicCred = new BasicAuthCredential(cred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
TfsConfigurationServer _configurationServer = new TfsConfigurationServer(tfsUri, tfsCred);
ReadOnlyCollection <Microsoft.TeamFoundation.Framework.Client.CatalogNode> _collectionNodes =
_configurationServer.CatalogNode.QueryChildren(
new[] {
CatalogResourceTypes.ProjectCollection
}, false, CatalogQueryOptions.None);
Microsoft.TeamFoundation.Framework.Client.CatalogNode collectionNode = _collectionNodes.FirstOrDefault(c => c.Resource.DisplayName == "MyProjCollection");
var tpcId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
var tpc = _configurationServer.GetTeamProjectCollection(tpcId);
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore _wiStore = tpc.GetService<TF_WIT_Client.WorkItemStore>();
I have two domain accounts, both have equal permissions to TFS. If I use any of these accounts along with their respective password, the code works fine and the WorkItemStore is retrieved.
However, If I impersonate the application with the first domain account and use the second account for authentication with TFS, I get the following error:
System.InvalidOperationException occurred HResult=0x80131509
Message=Collection node not found: ProjectCollectionName 'MyProjCollection'Inner Exception 1: COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
Due to the way the application is written, skipping impersonation is not an option. Has anyone faced this issue before and/or knows a workaround? Thanks.
In order for impersonation to work, the user that the process is running as must have the “Make requests on behalf of others
” permission for this collection. If the user does not have this permission then you are going to see an Access Denied error message.
So, please give the user “Make requests on behalf of others
” permission first.
You can reference below articles to use TFS Impersonation:
User contributions licensed under CC BY-SA 3.0