## OperationContext.Current may return null when called in a using clause ### Scope Edge ### Version Introduced 4.6.2 ### Version Reverted ### Source Analyzer Status Investigating ### Change Description may return `null` and a may result if all of the following conditions are true: - You retrieve the value of the property in a method that returns a or . - You instantiate the object in a `using` clause. - You retrieve the value of the property within the `using statement`. For example: ```csharp using (new OperationContextScope(OperationContext.Current)) { OperationContext context = OperationContext.Current; // OperationContext.Current is null. // ... } ``` - [X] Quirked - [ ] Build-time break ### Recommended Action To address this issue, you can do the following: - Modify your code as follows to instantiate a new non-`null` object: ```csharp OperationContext ocx = OperationContext.Current; using (new OperationContextScope(OperationContext.Current)) {     OperationContext.Current = new OperationContext(ocx.Channel);     // ... } ``` - Install the latest update to the .NET Framework 4.6.2, or upgrade to a later version of the .NET Framework. This disables the flow of the in and restores the behavior of WCF applications in the .NET Framework 4.6.1 and earlier versions. This behavior is configurable; it is equivalent to adding the following app setting to your configuration file: ```xml ``` If this change is undesirable and your application depends on execution context flowing between operation contexts, you can enable its flow as follows: ```xml ``` ### Affected APIs - `P:System.ServiceModel.OperationContext.Current` ### Category Windows Communication Foundation (WCF)