I am completely shocked by this and the endless google / stackoverflow searches did not help. I use the Visual Studio SDK 2012 to connect to TFS 2012 and request a work item store. The code below works fine both in a console application and in an ASP.NET MVC application that does not use authentication or in any script running on my local computer. However, I get a COMException when I try to create an instance of WorkItemStore from an MVC application that has been deployed to the server and uses (Windows) authentication.
It doesn't matter if I have a <authentication mode="Windows" /> element in my web.config or not; as long as there is a [Authorize] attribute on my controller or any of its action methods, I get an exception as soon as the last line of code below is called. If I remove the [Authorize] attribute, an exception will not occur. If I call the code below at some point before calling the code decorated with [Authorize] , an exception does not occur. Somehow using AuthorizeAttibute raises this exception.
Any ideas on how to solve this problem? Or at least to more accurately identify the real root problem? I would really like to understand what is happening here.
Uri tfsAddress = new Uri("http://tfs-address:8080/tfs/DefaultCollection"); var myCreds = new NetworkCredential("userName", "password", "domain"); var tfsCreds = new TfsClientCredentials(new WindowsCredential(myCreds), false); var defaultCollection = new TfsTeamProjectCollection(tfsAddress, tfsCreds); defaultCollection.EnsureAuthenticated(); var store = defaultCollection.GetService<WorkItemStore>();
Stack trace:
[COMException (0x80004005): HRESULT error E_FAIL was returned from a call to the COM component.]
Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.DataStoreNative.BeginDataStoreInit (descriptor IntPtr, String defaultCachePath, String instanceId, Int32 cacheVersion) +0
Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.Datastore.BeginDataStoreInit (String defaultCachePath, String instanceId, Int32 cacheVersion) +56
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.InitializeInternal () +598
Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.Microsoft.TeamFoundation.Client.ITfsTeamProjectCollectionObject.Initialize (TfsTeamProjectCollection TeamProjectCollection command) +23
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.InitializeTeamFoundationObject (String fullName, object instance) +43
Microsoft.TeamFoundation.Client.TfsConnection.CreateServiceInstance (build assembly, String fullName) +91
Microsoft.TeamFoundation.Client.TfsConnection.GetServiceInstance (type serviceType, Object serviceInstance) +200
Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.GetServiceInstance (enter serviceType, Object serviceInstance) +439
Microsoft.TeamFoundation.Client.TfsConnection.GetService (type serviceType) +241
Microsoft.TeamFoundation.Client.TfsConnection.GetService () +58