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.

456 ❘ ChaPTer 18 Assemblies<br />

Be sure to register the new version of the shared assembly SharedDemo again in the GAC, using gacutil.<br />

If the referenced version cannot be found, you will get a System.IO.FileLoadException, because the<br />

binding to the correct assembly failed.<br />

With a successful run, you can see the full name of the referenced assembly:<br />

SharedDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken= f946433fdae2512d<br />

This client program can now be used to test different configurations of this shared component.<br />

binding to assembly Versions<br />

With a configuration file, you can specify that the binding should happen to a different version of a shared<br />

assembly. Assume that you create a new version of the shared assembly SharedDemo with major <strong>and</strong> minor<br />

versions 1.1. Maybe you don’t want to rebuild the client but just want the new version of the assembly to<br />

be used with the existing client instead. This is useful in cases where either a bug is fixed with the shared<br />

assembly or you just want to get rid of the old version because the new version is compatible.<br />

By running gacutil.exe, you can see that the versions 1.0.0.0 <strong>and</strong> 1.0.3300.0 are installed for the<br />

SharedDemo assembly:<br />

> gacutil -l SharedDemo<br />

Microsoft (R) .<strong>NET</strong> Global Assembly Cache Utility. Version 4.0.21006.1<br />

Copyright (c) Microsoft Corporation. All rights reserved.<br />

The Global Assembly Cache contains the following assemblies:<br />

SharedDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f946433fdae2512d,<br />

processorArchitecture=x86<br />

SharedDemo, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=f946433fdae251<br />

2d, processorArchitecture=x86<br />

Number of items = 2<br />

Figure 18-14 shows the manifest of the client<br />

application where the client references version<br />

1.0.0.0 of the assembly SharedDemo.<br />

Now, again, an application configuration<br />

file is needed. As before, the assembly that<br />

is redirected needs to be specified with the<br />

element. This element<br />

identifies the assembly using the name, culture,<br />

<strong>and</strong> public key token. For a redirect to a different<br />

version, the element is<br />

used. The oldVersion attribute specifies what<br />

version of the assembly should be redirected to a<br />

new version. With oldVersion you can specify<br />

a range like the one shown that all assemblies<br />

figure 18-14<br />

from version 1.0.0.0 to 1.0.3300.0 should be<br />

redirected. The new version is specified with the newVersion attribute.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!