CHAPTER 14 BUILDING AND CONFIGURING CLASS LIBRARIES
Figure 14-10. CarLibrary.dll now resides under the MyLibraries subdirectory
Try to run your client program again by double-clicking the executable. Because the CLR could not
locate an assembly named CarLibrary directly within the application directory, you are presented with a
rather nasty unhandled FileNotFoundException exception.
To instruct the CLR to probe under the MyLibraries subdirectory, create a new configuration file
named CSharpCarClient.exe.config using any text editor, and save the file in the folder containing the
CSharpCarClient.exe application, which, in this example is C:\MyApp. Open this file and enter the
following content exactly as shown (be aware that XML is case sensitive!):
.NET *.config files always open with a root element named . The nested
element may specify an element, which nests a further element named .
The privatePath attribute is the key point in this example, as it is used to specify the subdirectories
relative to the application directory where the CLR should probe.
Once you’ve finished creating CSharpCarClient.exe.config, run the client by double-clicking the
executable in Windows Explorer. You should find that CSharpCarClient.exe executes without a hitch (if
this is not the case, double-check your *.config file for typos).
Do note that the element does not specify which assembly is located under a given
subdirectory. In other words, you cannot say, “CarLibrary is located under the MyLibraries subdirectory,
but MathLibrary is located under the OtherStuff subdirectory.” The element simply instructs
the CLR to investigate all specified subdirectories for the requested assembly until the first match is
encountered.
528