Free mag vol1 | Page 602

CHAPTER 14  BUILDING AND CONFIGURING CLASS LIBRARIES Here’s another example: you have shipped the first version of a bug-free assembly (1.0.0.0), and after a month or two, you add new functionality to the assembly to yield version 2.0.0.0. Obviously, existing client applications that were compiled against version 1.0.0.0 have no clue about these new types, given that their code base makes no reference to them. New client applications, however, wish to make reference to the new functionality in version 2.0.0.0. Under .NET, you are free to ship version 2.0.0.0 to the target machines, and have version 2.0.0.0 run alongside the older version 1.0.0.0. If necessary, existing clients can be dynamically redirected to load version 2.0.0.0 (to gain access to the implementation refinements), using an application configuration file without needing to recompile and redeploy the client application. Freezing the Current Shared Assembly To illustrate how to dynamically bind to a specific version of a shared assembly, open Windows Explorer and copy the current version of the compiled C arLibrary.dll assembly (1.0.0.0) into a distinct subdirectory (I called mine CarLibrary Version 1.0.0.0) to symbolize the freezing of this version (see Figure 14-22). Figure 14-22. Freezing the current version of CarLibrary.dll Building a Shared Assembly Version 2.0.0.0 Now, open your existing CarLibrary project and update your code base with a new enum type named MusicMedia that defines the following four possible musical devices: // Which type of music player does this car have? public enum MusicMedia { musicCd, musicTape, musicRadio, musicMp3 } As well, add a new public method to the Car type that allows the caller to turn on one of the given media players (be sure to import the System.Windows.Forms namespace if necessary), like so: 544