C# Programmer[ap]s Cookbook

Problem

You want to create a component host that can host more than one version of the same object.

Solution

Install all versions of the object into the GAC, and explicitly register each version at a different URI endpoint.

Discussion

.NET Remoting doesn't include any intrinsic support for versioning. When a client creates a remote object, the component host automatically uses the version in the local directory or, in the case of a shared assembly, the latest version from the GAC. To support multiple versions, you have three choices:

The last option is the most flexible in cases where you need to support multiple versions. For example, consider the following configuration file, which registers two versions of the RemoteObjects assembly at two different endpoints. Notice that you need to include the exact version number and public key token when using assemblies from the GAC. You can find this information by viewing the assembly in the Windows Explorer GAC plug-in (browse to C:\[WindowsDir]\Assembly).

<configuration> <system.runtime.remoting> <application> <service> <!-- The type information is split over two lines to accommodate the bounds of the page. In the configuration file, this information must all be placed on a single line. --> <wellknown mode="SingleCall" type="RemoteObjects.RemoteObject, RemoteObjects, Version 1.0.0.1, Culture=neutral, PublicKeyToken=8b5ed84fd25209e1" objectUri="RemoteObj" /> <wellknown mode="SingleCall" type="RemoteObjects.RemoteObject, RemoteObjects, Version 2.0.0.1, Culture=neutral, PublicKeyToken=8b5ed84fd25209e1" objectUri="RemoteObj_2.0" /> </service> <channels> <channel ref="tcp server" port="9080" /> </channels> </application> </system.runtime.remoting> </configuration>

The client configuration file won't change at all (aside from updating the URI, if required). The client "chooses" the version it wants to use by using the corresponding URI.

Категории