title: Unhandled Aggregate Exception
body: <p>I have followed the tutorial in ( <a href="http://www.c-sharpcorner.com/UploadFile/a6fd36/understand-self-host-of-a-web-apiC-Sharp/" rel="nofollow">http://www.c-sharpcorner.com/UploadFile/a6fd36/understand-self-host-of-a-web-apiC-Sharp/</a> ) and ( <a href="http://www.c-sharpcorner.com/uploadfile/a6fd36/understanding-how-to-call-the-web-api-from-a-client-applica/" rel="nofollow">http://www.c-sharpcorner.com/uploadfile/a6fd36/understanding-how-to-call-the-web-api-from-a-client-applica/</a> ) but seem to still be getting System.AggregateException on </p>
  
  <pre><code>                 //Call HttpClient.GetAsync to send a GET request to the appropriate URI   
              HttpResponseMessage resp = client.GetAsync("api/books").Result;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>                var resp = client.GetAsync(string.Format("api/books/{0}", id)).Result;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>                var resp = client.GetAsync(query).Result;
  </code></pre>
  
  <p>The error states: An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll</p>
  
  <p>Exception Detail - </p>
  
  <pre><code>  System.AggregateException was unhandled
    HResult=-2146233088
     Message=One or more errors occurred.
     Source=mscorlib
    StackTrace:
     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
     at System.Threading.Tasks.Task`1.get_Result()
     at TestClient.Program.ListAllBooks() in c:\Users\wa\Documents\Visual Studio 2013\Projects\SelfHost\TestClient\Program.cs:line 35
     at TestClient.Program.Main(String[] args) in c:\Users\wa\Documents\Visual Studio 2013\Projects\SelfHost\TestClient\Program.cs:line 20
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
     at System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.Net.Http.HttpRequestException
     HResult=-2146233088
     Message=An error occurred while sending the request.
     InnerException: System.Net.WebException
          HResult=-2146233079
          Message=Unable to connect to the remote server
          Source=System
          StackTrace:
               at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
               at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
          InnerException: System.Net.Sockets.SocketException
               HResult=-2147467259
               Message=No connection could be made because the target machine actively refused it [::1]:8080
               Source=System
               ErrorCode=10061
               NativeErrorCode=10061
               StackTrace:
                    at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
                    at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception)
               InnerException: 
  </code></pre>
  
  <p>Any Ideas?</p>
  
  <p>Thank You</p>