How to successfully connect to Workstem TFS 2010 repository?

I tried two ways to connect to workitemstore for the TFS server in which we work. Attempt A was to connect to the configuration server and use the GetService<WorkItemStore>() method. This always returns null.

Attempt B was to connect to TfsTeamProjectCollection and use the GetService<WorkItemStore>() method or pass the project collection to the WorkItemStore constructor. In attempt B, I get an exception: "Error HRESULT E_FAIL was returned from a call to the COM component." The only information I can find on this seems to indicate some permissions issues, but I confirmed that I am authenticated as read-only user to the entire collection of projects, and I connect and intervene accordingly through the VS 2011 preview.

This is how I connect ...

  public TfsConfigurationServer GetConfigurationServer() { Uri tfsUri = new Uri(configs.TfsUri); TfsConfigurationServer server = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri, credProvider); server.Authenticate(); if (server.HasAuthenticated == false) throw new InvalidOperationException("You can't authenticate against the tfs instance."); return server; } public TfsTeamProjectCollection GetProjectCollectionInstance(string projectCollectionName) { Uri tfsUri = new Uri(configs.TfsUri + "/" + projectCollectionName); TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri, credProvider); collection.Authenticate(); if (collection.HasAuthenticated == false) throw new InvalidOperationException("You can't authenticate against the tfs instance."); return collection; } 

and this is how I try to get WorkItemStore (stupid code to illustrate the problem) ...

  public WorkItemProvider() { if (workItems == null) workItems = ServerProvider.ServerInstance.GetService<WorkItemStore>(); if (workItems == null) workItems = ServerProvider.ProjectCollectionInstance.GetService<WorkItemStore>(); if (workItems == null) workItems = new WorkItemStore(ServerProvider.ProjectCollectionInstance); if (workItems == null) throw new NullReferenceException("Couldn't load work item store."); } 

I am not on the same domain as the server, but I authenticate as a domain user using ICredentialsProvider, and I have verified that I am authenticated as this user. Any pointers would be helpful.

+6
source share
2 answers

Make sure this does what you need:

 using System; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.WorkItemTracking.Client; namespace GetsWorkItem { class Program { static void Main() { TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<TFS>:8080/tfs/<COLLECTION>")); WorkItemStore workItemStore= (WorkItemStore) teamProjectCollection.GetService(typeof (WorkItemStore)); WorkItem workItem = workItemStore.GetWorkItem(1234); } } } 
+2
source

I believe this article can answer your question. It says that if you create an instance of your WorkItemStore a little differently, you will get another exception:

System.TypeInitializationException: The type initializer for 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore' threw an exception. —> System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727′ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

The fix is ​​a simple change to web.config, adding the following:

 <?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> </configuration> 

Hope this helps! Worked for me when I got the same error.

0
source

Source: https://habr.com/ru/post/907732/


All Articles