I'm trying to connect to TeamFoundationServer hosted at visualstudio.com using its client API with a Console Application, but I get this error:
TF400813: Resource not available for anonymous access. Client
My code:
private static void Main(string[] args)
{
    Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");
    TfsTeamProjectCollection collection =
        new TfsTeamProjectCollection(
            collectionUri,
            new System.Net.NetworkCredential(@"[email protected]", "MyPassword"));
    WorkItemStore workItemStore = collection.GetService<WorkItemStore>(); 
}
                You have to call the EnsureAuthenticated() method from TfsTeamProjectCollection:
private static void Main(string[] args)
{
    Uri collectionUri = new Uri("https://MyName.visualstudio.com/DefaultCollection");
    NetworkCredential credential = new NetworkCredential("USERNAME", "PASSWORD");
    TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, credential);
    teamProjectCollection.EnsureAuthenticated();
    WorkItemStore workItemStore = teamProjectCollection.GetService<WorkItemStore>();
    WorkItemCollection workItemCollection = workItemStore.Query("QUERY HERE");
    foreach (var item in workItemCollection)
    {
        //Do something here.
    }
}
I hope it has solved your problem.
Set up alternate credentials for your account.  You can use alternate credentials for the command-line clients and as a NetworkCredential parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With