15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Configuring .neT applications ❘ 453<br />

➤<br />

from the machine configuration. The application configuration file should be the preferred place for<br />

application-specific settings so that the machine configuration file stays smaller <strong>and</strong> more manageable.<br />

A machine configuration file is located in %runtime_install_path%\config\Machine.config.<br />

Publisher policy files can be used by a component creator to specify that a shared assembly is<br />

compatible with older versions. If a new assembly version just fixes a bug of a shared component,<br />

it is not necessary to put application configuration files in every application directory that uses this<br />

component; the publisher can mark it as compatible by adding a publisher policy file instead. In case<br />

the component doesn’t work with all applications, it is possible to override the publisher policy setting<br />

in an application configuration file. In contrast to the other configuration files, publisher policy files<br />

are stored in the GAC.<br />

How are these configuration files used How a client finds an assembly (also called binding) depends on<br />

whether the assembly is private or shared. Private assemblies must be in the directory of the application or<br />

in a subdirectory thereof. A process called probing is used to find such an assembly. If the assembly doesn’t<br />

have a strong name, the version number is not used with probing.<br />

Shared assemblies can be installed in the GAC or placed in a directory, on a network share, or on a web site.<br />

You specify such a directory with the configuration of the codeBase shortly. The public key, version, <strong>and</strong><br />

culture are all important aspects when binding to a shared assembly. The reference of the required assembly<br />

is recorded in the manifest of the client assembly, including the name, the version, <strong>and</strong> the public key token.<br />

All configuration files are checked to apply the correct version policy. The GAC <strong>and</strong> code bases specified<br />

in the configuration files are checked, followed by the application directories, <strong>and</strong> probing rules are then<br />

applied.<br />

binding to assemblies<br />

You’ve already seen how to install a shared assembly to the GAC. Instead of installing a shared assembly to<br />

the GAC, you can configure a specific shared directory by using configuration files. This feature can be used<br />

if you want to make the shared components available on a server. Another possible scenario arises if you<br />

want to share an assembly between your applications, but you don’t want to make it publicly available in the<br />

GAC, so you put it into a shared directory instead.<br />

There are two ways to find the correct directory for an assembly: the codeBase element in an XML<br />

configuration file, or through probing. The codeBase configuration is available only for shared assemblies,<br />

<strong>and</strong> probing is done for private assemblies.<br />

<br />

The can be configured with an application configuration file. The following application<br />

configuration file redirects the search for the assembly SharedDemo to load it from the network:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The element has the attributes version <strong>and</strong> href. With version, the original referenced<br />

version of the assembly must be specified. With href, you can define the directory from which the assembly<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!