title: TFS .Net REST API access with PAT
body: <p>I have a code in C# that access TFS Rest API.
  When I use the following code:</p>
  
  <pre><code>VssConnection connection = new VssConnection(orgUrl, new VssCredentials());
  </code></pre>
  
  <p>I get the results I need.</p>
  
  <p>When trying to set the credentials:</p>
  
  <pre><code>VssConnection connection = new VssConnection(orgUrl, credentials);
  </code></pre>
  
  <p>I get an error.</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll</p>
  </blockquote>
  
  <p>The error occurs when the following code line is committed:</p>
  
  <pre><code>WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result;
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>static void Main(string[] args)
  {
              Uri orgUrl = new Uri("my uri");                       
              string personalAccessToken = "my token"; 
              int workItemId = 486915;   
  
          // Create a connection
          VssCredentials credentials = new VssBasicCredential("", personalAccessToken);
          VssConnection connection = new VssConnection(orgUrl, credentials);
  
          //VssConnection connection = new VssConnection(orgUrl, new VssCredentials());
  
          // Show details a work item
          ShowWorkItemDetails(connection, workItemId);
  
          Console.ReadLine();
  }
  
  public static void ShowWorkItemDetails(VssConnection connection, int workItemId)
  {
          // Get an instance of the work item tracking client
          WorkItemTrackingHttpClient witClient = connection.GetClient&lt;WorkItemTrackingHttpClient&gt;();
  
          // Get the specified work item
          WorkItem workitem = witClient.GetWorkItemAsync(workItemId).Result;
  
              // Output the work item's field values
              foreach (var field in workitem.Fields)
              {
                  Console.WriteLine("  {0}: {1}", field.Key, field.Value);
              }
  }
  </code></pre>