Friday 18 October 2013

Fetch WorkItems with TFS API WorkItemStore NullReferenceException

While trying to retrieve TFS workitems, following code snippet is usually used:

var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<server>:<port>/tfs/<collection>"));
var _workItemStore = projectCollection.GetService<WorkItemStore>();

This works well with .NET 4.5 Framework. But if the installed version is lower than 4.5 a NullReferenceException is thrown. This can be fixed by using a different way of initializing WorkItemStore object as below:

var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://<server>:<port>/tfs/<collection>"));
var _workItemStore = new WorkItemStore(projectCollection);

Hope this is helpful.

No comments:

Post a Comment