■
Note
Technically speaking, if a copy of the requested assembly cannot be found within the client’s application
directory, the CLR will also attempt to locate a client subdirectory with the exact same name as the assembly’s
friendly name (e.g., C:\MyClient\CarLibrary). If the requested assembly resides within this subdirectory, the CLR
will load the assembly into memory.
Configuring Private Assemblies
While it is possible to deploy a .NET application by simply copying all required assemblies to a sin-
gle folder on the user’s hard drive, you will most likely wish to define a number of subdirectories to
group related content. For example, assume you have an application directory named C:\MyApp
that contains CSharpCarClient.exe. Under this folder might be a subfolder named MyLibraries that
contains CarLibrary.dll.
Regardless of the intended relationship between these two directories, the CLR will
not probe
the MyLibraries subdirectory unless you supply a configuration file. Configuration files contain var-
ious XML elements that allow you to influence the probing process. Configuration files must have
the same name as the launching application and take a *.config file extension, and they must be
deployed in the client’s application directory. Thus, if you wish to create a configuration file for
CSharpCarClient.exe, it must be named CSharpCarClient.exe.config and located (for this example)
under the C:\MyApp directory.
To illustrate the process, create a new directory on your C drive named MyApp using Windows
Explorer. Next, copy CSharpCarClient.exe and CarLibrary.dll to this new folder, and run the
program by double-clicking the executable. Your program should run successfully at this point
(remember, the assemblies are not registered!). Next, create a new subdirectory under C:\MyApp
named MyLibraries (see Figure 15-12), and move CarLibrary.dll to this location.
Try to run your client program again. Because the CLR could not locate an assembly named
“CarLibrary” directly within the application directory, you are presented with a rather nasty unhan-
dled FileNotFoundException exception.
To instruct the CLR to probe under the MyLibraries subdirectory, create a new configuration
file named CSharpCarClient.exe.config and save it in the same folder containing the
CSharpCarClient.exe application, which in this example would be C:\MyApp. Open this file
and enter the following content exactly as shown (be aware that XML is case sensitive!):
privatePath="MyLibraries"/>
C H A P T E R 1 5
Do'stlaringiz bilan baham: |