[ Pobierz całość w formacie PDF ]
.Now, however, you have started a new project, which creates anew solution.This solution is in a different directory, and therefore has no knowledgeof the Healthcare component. 05 2203-x CH04 5/1/01 12:52 PM Page 8888 Chapter 4: Bui l di ng Cl asses and Assembl i es wi th VB.NETTo have the new project use the Healthcare component, make sure that you are on the.NET Framework tab of the Add Reference dialog box and click the Browse button.Navigate to the My Documents\Visual Studio Projects\Healthcare\bin folder andchoose Healthcare.dll.The References node in the Solution Explorer window nowshows the Healthcare component.Your application can now use the Healthcare component.You can create objects bytyping the following code:Dim Patient As New Healthcare.Patient()You can always use the Import command to import the Healthcare namespace, soyou could instantiate objects with just this code:Dim Patient As New Patient()How.NET Locates AssembliesThink back to COM: When a program makes a call to a component, the ServiceControl Manager goes to the registry, looks up the component information, locatesthe object, creates it, and returns to the calling application a pointer to the newly cre-ated object.NET doesn t use the registry, so it has to use a different mechanism forlocating assemblies that are referenced in an application (or in another assembly).The full details are not critical to understanding how to develop components, but abasic understanding of the process is important for troubleshooting.Step 1: Getting the Reference InformationYour application attempts to call a referenced assembly.The reference contains thefollowing information about the assembly:" Name" Version" Culture" Public Key (for strongly named assemblies)The runtime uses this information to try to locate the assembly, using the followingsteps.Step 2: Looking at the Configuration FileThe configuration file is a powerful concept.You can create a configuration file tohandle any reference information that might change.For example, if you think youwill need to update the particular version of an assembly used by your application, 05 2203-x CH04 5/1/01 12:52 PM Page 89Compi l i ng the Assembl y 89you can store that information in a configuration file.You can also force an applica-tion to bind to only the versions of components that were available when the applica-tion was built.This is called Safe Mode.The configuration file is an XML file.Step 3: Using CodeBases or ProbingIf you want to prevent probing, you can specify a CodeBase value in the configura-tion file.When the runtime loads the file pointed to by the CodeBase, it checks theversion information to make sure it matches what is in the application s reference.By default, if the assembly pointed to by the CodeBase is the same version or higher,the binding will occur.If there is no CodeBase, the runtime looks first in the GAC if the assembly isstrongly named.If the assembly is private, the search is performed only in the appli-cation s root directory, referred to as the AppBase.The runtime sees a reference to anassembly in the application, such as Healthcare, and looks for the assembly by firstsearching for Healthcare.DLL.If the assembly is not found in the AppBase directory, the runtime searches based onthe path set up in the configuration file.This path is specified with thetag, as such:The runtime automatically appends some other information to the search path.Forexample, if the assembly you are searching for is Healthcare, the runtime looks inAppBase\Healthcare.It also looks in the bin directory, so it searches AppBase\bin.Because you specified MyAssemblies in the tag, the runtime searchesAppBase\MyAssemblies.Finally, it appends the locale, so if the locale is de, thesearch path will include AppBase\Bin\de, AppBase\Healthcare\de, andAppBase\MyAssembies\de.Step 4: The GACRecall that the Global Assembly Cache is a cache for assemblies to be used by multi-ple applications on the same machine.Even if an assembly is found through probingor CodeBases, the runtime looks for updated versions in the GAC, provided you havenot turned off this functionality.If a higher version exists in the GAC, it is used.If no assembly was found using a CodeBase or probing, the runtime searches theGAC for a match.If a matching assembly is found, it is used.To add assemblies to, remove assemblies from, or view assemblies in the GAC, usethe gacutil.exe console application, provided by the Framework.The GAC is also adirectory, so you can add assemblies to the GAC merely by copying them into thedirectory. 05 2203-x CH04 5/1/01 12:52 PM Page 9090 Chapter 4: Bui l di ng Cl asses and Assembl i es wi th VB [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • wpserwis.htw.pl