Reputation: 251
I'm trying to get test plans by using TFS API.
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://xxxxxxx:8080/tfs/DefaultCollection"));
var service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
The variable "service" always returns null.
Do you have any idea, why?
Upvotes: 5
Views: 1669
Reputation: 137
Perhaps you're linking against different versions of reference assemblies, mixing different versions of Visual Studio assemblies? Example:
Microsoft.TeamFoundation.Client
v11.0 (VS 2012)Microsoft.TeamFoundation.TestManagement.Client
v12.0 (VS 2013)I had the same problem of GetService<ITestManagementService>()
always returning null, even when GetService<VersionControlServer>()
would return good (non-null) value.
The solution posted in MSDN - VersionControlServer always returns null worked for me: I had references to some v11.0 (VS2012) and v12.0 (VS2013) assemblies. Changing all references to v11.0 fixed it for me.
Upvotes: 2
Reputation: 5223
Try to make sure you that you are authenticated to the Team Project Collection before calling the Get Service command. This code snippet works correctly for me:
TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://tfs.companyname.com/tfs/DefaultCollection"));
tpc.EnsureAuthenticated();
ITestManagementService service = tpc.GetService<ITestManagementService>();
Upvotes: 4