Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OperationContext is null after async method using .net 4.6.2

I have a problem with OperationContext getting null after an async operation is called (and my threadid changes).

I know this is a know issue and I've gone threw some StackOverflow questions regarding the issue.

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

OperationContext.Current Async Improvements

WCF now has the ability to include OperationContext.Current with ExecutionContext so that the OperationContext flows through asynchronous continuations. With this improvement, WCF allows CurrentContext to propagate from one thread to another thread. This means that even if there’s a context switch between calls to OperationContext.Current, it’s value will flow correctly throughout the execution of the method.

Is there anything special I need to do in order to get this supported on my end? I'm using VS 2013, updated the framework to 4.6.2 and installed the dev-pack. I've changed my project to use Framework 4.6.2 and I still get a null OperationContext after an async call.

like image 848
Amir Popovich Avatar asked Sep 26 '16 12:09

Amir Popovich


2 Answers

Per the answer from Tomasz, make sure the following is in your app config:

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

For more information take a look at https://github.com/Microsoft/dotnet/issues/403 where MS acknowledges that this is, in fact, a breaking change. Seems like this could easily break a lot applications out in the field.

like image 88
user2116722 Avatar answered Oct 29 '22 17:10

user2116722


After installing KB4013429 operation context async flow is disabled by default. To enable it (and use functionality fixed in 4.6.2) you need to set wcf:disableOperationContextAsyncFlow flag to "false" in your app config. (I haven't found any information about this flag, discovered it while fixing issue with incorrect propagation of OperationContext).

like image 1
Tomasz Kus Avatar answered Oct 29 '22 17:10

Tomasz Kus