COM+ Context Attributes

You can decorate (apply attributes to) your class with two context-related attributes. The attribute MustRunInClientContext informs COM+ that the class must be activated in its creator’s context:

[MustRunInClientContext(true)]
public class MyComponent :ServicedComponent
{...}

When you register the class above with COM+, the “Must be activated in caller’s context” checkbox on the component’s Activation tab is selected in the Component Services Explorer. If you do not use this attribute, the registration process uses the default COM+ setting when registering the component with COM+ —not enforcing same-context activation. As a result, using MustRunInClientContext with a false parameter passed to the constructor is the same as using the COM+ default:

[MustRunInClientContext(false)]

Using attributes with the COM+ default values (such as constructing the MustRunInClientContext attribute with false) is useful when you combine it with the /reconfig switch of RegSvcs. For example, you can undo any unknown changes made to your component configuration using the Component Services Explorer and restore the component configuration to a known state.

The MustRunInClientContext attribute class has an overloaded default constructor. If you use MustRunInClientContext with no parameters, the default constructor uses true for the attribute value. As a result, the following two statements are equivalent:

[MustRunInClientContext]
[MustRunInClientContext(true)]

The second COM+ context-related ...

Get COM & .NET Component Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.