2

I am using VS 2012 and set the target framework 4.0.

public async Task<HttpResponseMessage> GetResponse(Uri url)             
{                 
    this.httpClient.DefaultRequestHeaders.Accept.Clear();                 
    HttpResponseMessage response = await this.httpClient.GetAsync(url);                 
    response.EnsureSuccessStatusCode();             
}

Error:

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.CompilerServices.AsyncTargetingPack.Net4
StackTrace:
Server stack trace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean  setImpersonationContext) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClassa.<OnCompletedInternal>b__0(Task param0)
        Exception rethrown at [0]: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state)
           at System.Threading.QueueUserWorkItemCallback.WaitCallback_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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
           at System.Threading.ThreadPoolWorkQueue.Dispatch()
           at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
      InnerException: 
    -------------------------------------------------

I have installed "Microsoft.CompilerServices.AsyncTargetingPack" from NuGet, but still getting this error. Any suggestion.

3
  • Have you tried using Microsoft.Bcl.Async instead of Microsoft.CompilerServices.AsyncTargetingPack? Commented Feb 19, 2013 at 15:19
  • yes, i used Microsoft.Bcl.Async link as well but still getting same error. Commented Feb 20, 2013 at 6:37
  • Take a look at my question. May be it will help you. Commented Mar 15, 2013 at 17:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.