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.

454 ❘ ChaPTer 18 Assemblies<br />

should be loaded. In the example, a path using the HTTP protocol is used. A directory on a local system or<br />

a share is specified by using href=“file://C:/WroxUtils/SharedDemo.dll”.<br />

<br />

When the is not configured <strong>and</strong> the assembly is not stored in the GAC, the runtime tries to<br />

find an assembly through probing. The .<strong>NET</strong> runtime tries to find assemblies with either a .dll or an<br />

.exe file extension in the application directory or in one of its subdirectories that has the same name as the<br />

assembly searched for. If the assembly is not found here, the search continues. You can configure search<br />

directories with the element in the section of application configuration files. This<br />

XML configuration can also be done easily by selecting the properties of the application with the .<strong>NET</strong><br />

Framework Configuration tool. You can configure the directories where the probing should occur by using<br />

the search path in the .<strong>NET</strong> Framework configuration.<br />

The XML file produced has these entries:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The element has just a single required attribute: privatePath. This application configuration<br />

file tells the runtime that assemblies should be searched for in the base directory of the application, followed<br />

by the bin <strong>and</strong> the util directory. Both directories are subdirectories of the application base directory. It’s<br />

not possible to reference a private assembly outside the application base directory or a subdirectory thereof.<br />

An assembly outside of the application base directory must have a shared name <strong>and</strong> can be referenced using<br />

the element, as you saw earlier.<br />

Versioning<br />

For private assemblies, versioning is not important because the referenced assemblies are copied with the<br />

client. The client uses the assembly it has in its private directories.<br />

This is, however, different for shared assemblies. This section looks at the traditional problems that can<br />

occur with sharing. With shared components, more than one client application can use the same component.<br />

The new version can break existing clients when updating a shared component with a newer version. You<br />

can’t stop shipping new versions because new features will be requested <strong>and</strong> introduced with new versions<br />

of existing components. You can try to program carefully to be backward compatible, but that’s not always<br />

possible.<br />

A solution to this dilemma could be an architecture that allows installation of different versions of shared<br />

components, with clients using the version that they referenced during the build process. This solves a lot of<br />

problems but not all of them. What happens if you detect a bug in a component that’s referenced from the<br />

client You would like to update this component <strong>and</strong> make sure that the client uses the new version instead<br />

of the version that was referenced during the build process.<br />

Therefore, depending on the type in the fix of the new version, you sometimes want to use a newer version,<br />

<strong>and</strong> you also want to use the older referenced version. The .<strong>NET</strong> architecture enables both scenarios.<br />

In .<strong>NET</strong>, the original referenced assembly is used by default. You can redirect the reference to a different<br />

version by using configuration files. Versioning plays a key role in the binding architecture — how the client<br />

gets the right assembly where the components live.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!