Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:54:48+00:00 2026-06-10T00:54:48+00:00

I have an Asp.Net application that calls some WCF service using a proxy generated

  • 0

I have an Asp.Net application that calls some WCF service using a proxy generated by svcutil.
The generated proxy has async methods in the APM pattern (BeginXxx, EndXxx).

I am using the async targeting pack in order to leverage the new async/await pattern, and my target platform is .net 4.0 (otherwise I wouldn’t have to use the async targeting pack).

I am using Task<T>.Factory.FromAsync to convert the APM pattern into a Task that I can await.

my code looks a little something like that (assuming the service method takes no parameters and returns an int:

int result = await Task<int>.Factory.FromAsync(proxy.BeginXxx, proxy.EndXxx, state: null);
HttpContext.Current.Items["reuslt"] = result;

The second line throws a NullReferenceException.

I am assuming that the reason is that the callback (which is everything that’s running after the await call) does not have the original synchronization context.

other methods (like Factory.StartNew) have overloads that receive a TaskScheduler that can be used to preserve the context.

The FromAsync Method also has overloads that receive a TaskScheduler, but none that have the begin method as an argument.

Assuming I do not want to start passing the Http context by hand as a method argument to all methods that get called after this line, how do I use the overload that gets a task scheduler or otherwise get .Net to respect my synchronization context?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:54:49+00:00Added an answer on June 10, 2026 at 12:54 am

    I suspect the problem is actually in the ASP.NET pipeline, not in the SynchronizationContext.

    The Async Targeting Pack enables async/await support, but there were a lot of changes in ASP.NET 4.5 to make it async-friendly, and the Targeting Pack doesn’t include that support.

    Try helping out the ASP.NET pipeline by using RegisterAsyncTask (for web forms) or AsyncManager (for MVC). Even then, there are some places in the pipeline that just can’t take asynchronous code (still true in ASP.NET 4.5, but at least 4.5 will detect this and throw an error).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET application that calls other web services through SSL (outside the
I have a small conundrum where I have an asp.net application that's using forms
I have an ASP.NET MVC3 application that I have built and it has two
I have an ASP.NET MVC application, with some RESTful services that I'm trying to
I have a WCF service in an ASP.NET AJAX app that is returning json.
I have an ASP.NET web application that presents data retrieved from a web service.
I have an ASP.NET web application that calls a .NET DLL, that in turn
I have an ASP.NET application that is hosted in timezone A and is being
I have an ASP.NET application that uses a custom .NET library (a .DLL file).
I have an ASP.Net Application that sends text messages to mobile phones. It does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.