FIX: CallContext objects are lost when you create a new serviced component

Article translations Article translations
Article ID: 319177 - View products that this article applies to.
This article was previously published under Q319177
Expand all | Collapse all

On This Page

SYMPTOMS

If you set CallContext objects before you create an instance of a serviced component in a client application, you may lose the CallContext objects after you create the object instance.

CAUSE

This problem occurs if the objects that you place in the CallContext derive from the ILogicalThreadAffinative interface. If you place these objects in the CallContext (by using the CallContext.SetData method) and then create an instance of a ServicedComponent object, the CallContext.GetData method for those objects returns null.

RESOLUTION

To resolve this problem, obtain the latest service pack for Microsoft .NET Framework. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
318836 INFO: How to Obtain the Latest .NET Framework Service Pack

WORKAROUND

To work around this problem, use one of the following methods:
  • If you only need to use CallContext items locally in your application, do not derive these items from ILogicalThreadAffinative.

    NOTE: The remoting system does not pass these objects across AppDomains.
  • If you want to use remoting servers with ServicedComponent objects, and if you want to flow CallContext to them, you must create an instance of your ServicedComponent objects before you place those items in the CallContext.

    If you cannot control this, you can store the contents of the CallContext before you create an instance of your ServicedComponent and then load the contents back in.
NOTE: You cannot take advantage of the CallContext feature in ServicedComponent applications. Microsoft does not support the use of CallContext from within ServicedComponent objects.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft .NET Framework Service Pack 2 (SP2).

MORE INFORMATION

With the CallContext object, you can send information along the channel from client to server or vice versa. CallContext provides a set of properties that are carried along with the execution code path (call chain).

This problem also occurs with all headers in the CallContext object.

Steps to Reproduce the Problem

  1. Define instances of a class to place in the CallContext:
    [Serializable]
    public class CtxObject : ILogicalThreadAffinative
    {
    	public string CtxString;
    	public CtxObject(){CtxString = "Some String" ;}
    }
    					
  2. Place one of these objects in a CallContext data slot, and then create an instance of a ServicedComponent:
    // Create CallContext object.
    CtxObject CtxObj = new CtxObject () ;                     
    
    // Set it in the CallContext.
    CallContext.SetData ("CtxObject", CtxObj) ;
    
    // Create the serviced component.
    MyServicedComponent MyObj = new MyServicedComponent () ;  
    
    // Retrieve the CallContext object (returns null).
    CtxObject CtxObj1 = (CtxObject) CallContext.GetData ("CtxObject") ;  
    					

Properties

Article ID: 319177 - Last Review: February 12, 2007 - Revision: 3.3
APPLIES TO
  • Microsoft .NET Framework Class Libraries 1.0
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Enterprise Services (included with the .NET Framework) 1.0
Keywords: 
kbvs2002sp1sweep kbbug kbfix kbnetframe100sp2fix kbremoting KB319177

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com