OperationContext is null after an asynchronous method using .net 4.6.2

I have a problem with OperationContext that gets null after calling async (and my stream changes).

I know this is a know-how problem, and I walked away with some StackOverflow questions regarding this problem.

In .net 4.6.2 there is a fix for the problem, as you can read here .

AsccContext.Current Performance Improvements

WCF now has the ability to enable OperationContext.Current with ExecutionContext so that OperationContext flows through asynchronous continuations. With this enhancement, WCF allows CurrentContext to propagate from one thread to another thread. This means that even if theres a context switch between calls to OperationContext.Current, its value will flow correctly during method execution.

Is there anything special I need to do to get this supported at my end? I am using VS 2013, updated the framework to 4.6.2 and installed dev-pack. I changed my project to use Framework 4.6.2 and I still get null OperationContext after an asynchronous call.

+6
source share
3 answers

After installing KB4013429, the async stream operation context is disabled by default. To enable it (and use the functionality installed in 4.6.2), you need to set the wcf: disableOperationContextAsyncFlow flag to false in your application configuration. (I did not find any information about this flag, I found it when fixing the problem with the incorrect distribution of OperationContext).

+1
source

In response from Tomasz, make sure the following is specified in your application configuration:

 <appSettings> <add key="wcf:disableOperationContextAsyncFlow" value="false" /> </appSettings> 

For more information, see https://github.com/Microsoft/dotnet/issues/403 , where MS acknowledges that this is essentially a violation. It seems like this can easily break many applications in the field.

+1
source

The behavior you are describing has made it a release of .NET 4.6.2, and we are aware of this. In fact, we are in the process of deploying the hotfix for this, and I expect it to be publicly available over the next few months.

Now known workarounds are to revert to version 4.6.1 of the framework or do something similar to this:

 OperationContext ocx = OperationContext.Current; using (new OperationContextScope(OperationContext.Current)) { OperationContext.Current = new OperationContext(ocx.Channel); // ... } 

Please let us know if you have further questions or comments.

0
source

All Articles