Deploying Private Assemblies

Team-Fly    

Developing XML Web Services and Server Components with Visual C#™ .NET and the .NET Framework, Exam Cram™ 2 (Exam 70-320)
By Amit Kalani, Priti Kalani

Table of Contents
Chapter 11.  Deployment


A private assembly is an assembly that is used by a single application. Private assemblies are the simplest to deploy. To deploy private assemblies, simply copy them to the application's base directory or one of its subdirectories. The CLR uses a process called probing to locate the privately deployed assemblies. You can have a certain degree of control over the probing process if you modify the binding policy by using the application configuration file.

Binding Policy for Privately Deployed Assemblies

Binding policy for privately deployed assemblies is a set of rules that instructs the CLR to search for an assembly in specific locations. The CLR uses a default binding policy, but you can use the application configuration file to specify binding rules that instruct the CLR to search for assemblies in additional locations.

For Windows applications, the application configuration file is application-specific and is located in the application's base directory (where the EXE file is located). The name of application configuration file is of the format ExecutableFileName.config. For example, the application configuration file for MathApp.exe would be MathApp.exe.config. In the case of Web applications, the application configuration file is stored in the application's root directory and is named web.config.

The application configuration file is an XML file that can contain different elements for configuring various aspects of an application. The element in which you'll be most interested in this section is the <probing> element, which specifies additional search locations for an assembly. A stripped-down version of an application configuration file containing the <probing> element is as follows:

 <?xml version="1.0"?> <configuration>   <runtime>     <assemblyBinding           xmlns="urn:schemas-microsoft-com:asm.v1">       <probing privatePath="bin\retail;bin\debug" />     </assemblyBinding>   </runtime> </configuration> 

You can use the privatePath attribute of the <probing> element to specify the subdirectories of the application's base directory that might contain assemblies. Each of these subdirectories is delimited with a semicolon.

How the CLR Binds to a Privately Deployed Assembly

The CLR takes the following steps to locate a privately deployed assembly:

  1. The CLR determines the assembly's name from the manifest of the requesting assembly.

  2. The CLR checks to see whether the requested assembly has already been loaded from the previous requests. If the assembly has been already loaded, the CLR binds to the assembly and stops searching any further.

  3. The CLR reads the application configuration file to check whether any private path hints are available in the <probing> element. If there are hints, the CLR uses these directory locations to search the assembly.

  4. If the referenced assembly has no culture information, the CLR uses the following locations in the given order to find the assembly:

     ApplicationBase\AssemblyName.dll ApplicationBase\AssemblyName\AssemblyName.dll ApplicationBase\PrivatePath1\AssemblyName.dll ApplicationBase\PrivatePath1\AssemblyName\AssemblyName.dll ApplicationBase\PrivatePath2\AssemblyName.dll ApplicationBase\PrivatePath2\AssemblyName\AssemblyName.dll ... ... ... ApplicationBase\AssemblyName.exe ApplicationBase\AssemblyName\AssemblyName.exe ApplicationBase\PrivatePath1\AssemblyName.exe ApplicationBase\PrivatePath1\AssemblyName\AssemblyName.exe ApplicationBase\PrivatePath2\AssemblyName.exe ApplicationBase\PrivatePath2\AssemblyName\AssemblyName.exe ... ... ... 

    Here ApplicationBase is the directory where the requesting application is installed, AssemblyName is the name of the assembly to search, and PrivatePath1 and PrivatePath2 are the hints provided in the <probing> element of the application configuration file. Note that the assembly name does not contain the extension; therefore, the CLR searches for both DLL and EXE files. If the assembly is found in any of these locations, the CLR binds to the assembly and does not search any further.

  5. If the referenced assembly has culture information, the following directories are searched:

     ApplicationBase\Culture\AssemblyName.dll ApplicationBase\Culture\AssemblyName\AssemblyName.dll ApplicationBase\PrivatePath1\Culture\AssemblyName.dll ApplicationBase\PrivatePath1\Culture\AssemblyName\AssemblyName.dll ApplicationBase\PrivatePath2\Culture\AssemblyName.dll ApplicationBase\PrivatePath2\Culture\AssemblyName\AssemblyName.dll ... ... ... ApplicationBase\Culture\AssemblyName.exe ApplicationBase\Culture\AssemblyName\AssemblyName.exe ApplicationBase\PrivatePath1\Culture\AssemblyName.exe ApplicationBase\PrivatePath1\Culture\AssemblyName\AssemblyName.exe ApplicationBase\PrivatePath2\Culture\AssemblyName.exe ApplicationBase\PrivatePath2\Culture\AssemblyName\AssemblyName.exe ... ... ... 

    Here Culture is a culture code corresponding to the assembly. If the assembly is found in any of these locations, the CLR binds to the assembly and does not search any further.

  6. If the CLR cannot locate the assembly after following the preceding steps, assembly binding fails.

graphics/note_icon.gif

Any version information contained in the private assembly is for informational purposes only. The CLR does not use the version information of a private assembly to bind to a specific version.


graphics/alert_icon.gif

If assembly binding fails, you can run the .NET Framework's Assembly Binding Log Viewer tool, fuslogvw.exe, from a Visual Studio .NET command prompt to investigate the problem. This tool gives you a reason for the bind failure, information about the calling assembly, and information on the search paths and policies that were used in the failed attempt to bind.


Using the .NET Framework Configuration Tool to Specify Additional Probing Location

If you want to add locations to the list that the CLR uses, you can use the .NET Framework Configuration tool. You'll find this tool in the Administrative Tools section of the Windows Control Panel. You can add any application to be managed by this tool and then use the properties of the application to add to the search path, as shown in Figure 11.1.

Figure 11.1. You can specify additional probing locations for an assembly by using the .NET Framework Configuration tool.

graphics/11fig01.gif

In fact, this tool stores this information in the application configuration file. You can also include probing information manually by modifying the application configuration file using any editor.


    Team-Fly    
    Top


    MCAD Developing XML Web Services and Server Components with Visual C#. NET and the. NET Framework Exam Cram 2 (Exam Cram 70-320)
    Managing Globally with Information Technology
    ISBN: 789728974
    EAN: 2147483647
    Year: 2002
    Pages: 179

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net