The code below provided in this answer did work well for a while but now its throwing Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: 'TF30063: You are not authorized to access https://{mysite}.visualstudio.com/.' again.
var credentials = new VssClientCredentials();
credentials.PromptType = CredentialPromptType.PromptIfNeeded;
var teamProjects = new TfsTeamProjectCollection(tfsCollectionUri, credentials);
teamProjects.EnsureAuthenticated(); // exception thrown
Q How can I fix this problem?
Update Strange enough,
- before executing
teamProjects.EnsureAuthenticated();
the debugger readsPromptIfNeeded
forcredentials.PromptType
. - after the exception has been thrown and the debugger has stopped the execution, it reads
DoNotPrompt
forcredentials.PromptType
.
Observation The above code works perfectly well in a console application but fails to work in a windows forms application (i.e. it throws an exception).
Q1 How can I make the above code work in a windows forms application?