Free mag vol1 | Page 608

CHAPTER 14  BUILDING AND CONFIGURING CLASS LIBRARIES Understanding the Element Application configuration files can also specify code bases. The element can be used to instruct the CLR to probe for dependent assemblies located at arbitrary locations (such as network end points, or an arbitrary machine path outside a client’s application directory). If the value assigned to a element is located on a remote machine, the assembly will be downloaded on demand to a specific directory in the GAC termed the download cache. Given what you have learned about deploying assemblies to the GAC, it should make sense that assemblies loaded from a element will need to be assigned a strong name (after all, how else could the CLR install remote assemblies to the GAC?). If you are interested, you can view the content of your machine’s download cache by supplying the /ldl option to gacutil.exe, like so: gacutil /ldl  Note Technically speaking, the element can be used to probe for assemblies that do not have a strong name. However, the assembly’s location must be relative to the client’s application directory (and, thus, is little more than an alternative to the element). To see the element in action, create a Console Application named CodeBaseClient, set a reference to CarLibrary.dll version 2.0.0.0, and update the initial file as follows: using using using using using System; System.Collections.Generic; System.Linq; System.Text; System.Threading.Tasks; using CarLibrary; namespace CodeBaseClient { class Program { static void Main(string[] args) { Console.WriteLine("***** Fun with CodeBases *****"); SportsCar c = new SportsCar(); Console.WriteLine("Sports car has been allocated."); Console.ReadLine(); } } } 550