CHAPTER 14 BUILDING AND CONFIGURING CLASS LIBRARIES
After you have compiled your client application, navigate to the directory that contains
SharedCarLibClient.exe using Windows Explorer and notice that Visual Studio has not copied
CarLibrary.dll to the client’s application directory. When you reference an assembly whose manifest
contains a .publickey value, Visual Studio assumes the strongly named assembly will most likely be
deployed to the GAC and, therefore, does not bother to copy the binary.
Exploring the Manifest of SharedCarLibClient
Recall that when you generate a strong name for an assembly, the entire public key is recorded in the
assembly manifest. On a related note, when a client references a strongly named assembly, its manifest
records a condensed hash value of the full public key, denoted by the .publickeytoken tag. If you open
the manifest of SharedCarLibClient.exe using ildasm.exe, you would find the following (your public key
token value will of course differ, as it is computed based on the public key value):
.assembly extern CarLibrary
{
.publickeytoken = (33 A2 BC 29 43 31 E8 B9 )
.ver 1:0:0:0
}
If you compare the value of the public key token recorded in the client manifest with the public key
token value shown in the GAC, you will find a dead-on match. Recall that a public key represents one
aspect of the strongly named assembly’s identity. Given this, the CLR will only load version 1.0.0.0 of
an assembly named CarLibrary that has a public key that can be hashed down to the value
33A2BC294331E8B9. If the CLR does not find an assembly meeting this description in the GAC (and did not
find a private assembly named CarLibrary in the client’s directory), a FileNotFoundException exception
is thrown.
Source Code The SharedCarLibClient application can be found under the Chapter 14 subdirectory.
Configuring Shared Assemblies
Like private assemblies, shared assemblies can be configured using a client *.config file. Of course,
because shared assemblies are deployed to a well-known location (the GAC), you don’t use the
element as you did for private assemblies (although if the client is using both shared and
private assemblies, the element may still exist in the *.config file).
You can use application configuration files in conjunction with shared assemblies whenever you
wish to instruct the CLR to bind to a different version of a specific assembly, effectively bypassing the
value recorded in the client’s manifest. This can be useful for a number of reasons. For example, imagine
that you have shipped version 1.0.0.0 of an assembly and later discover a major bug. One corrective
action would be to rebuild the client application to reference the correct version of the bug-free
assembly (say, 1.1.0.0) and redistribute the updated client and new library to every target machine.
Another option is to ship the new code library and a *.config file that automatically instructs the
runtime to bind to the new (bug-free) version. As long as the new version has been installed into the
GAC, the original client runs without recompilation, redistribution, or fear of having to update your
resume.
543