Assembly, module, application domain, Global Assembly Cache

Source: Internet
Author: User

FromProgramAdd resources and appdomain programming under. netArticleWe know that the Assembly assembly in the. net structure is a self-described installation unit, which runs in the application domain (appdomain. You must first load the assembly to the application domain before you can run the application, and the same assembly can be loaded to multiple application domains, according to these application domain for the AssemblyCodeDifferent usage methods generate the classification of the Assembly: private assembly and shared assembly.

1. Private assembly

We usually use private assembly. In this case, we create a local application project (or component). After compilation, we generate a private program assembly of the DLL or EXE type. When we use this type of assembly in other customer applications, we only need to add references. When such an assembly is used by multiple application domains, each application domain needs to copy the assembly, and multiple copies of the Assembly will also exist in the process.

2. Shared assembly

A shared assembly is opposite to a private assembly. It provides the ability of multiple application domains to access the same Assembly. In particular, only the same copy of the Assembly exists in the memory. This domain-specific code sharing greatly reduces memory resource usage. In addition, in most cases, the shared assembly is installed in the Global Assembly Cache but does not exist in the application-related directory. References to the shared Assembly do not generate file replication, naturally, no additional copies will be generated. Therefore, shared assembly cannot be deployed simply by using xcopy commands, but should be deployed Using MSI (Microsoft Windows Installer. Shared assembly is often used when components and main applications are not built by the same developer, or when a large application is distributed in several small projects.

Create a shared assembly with a unique name
Unlike private assemblies, shared assemblies follow many rules. In particular, a shared Assembly must have a unique name (called strongname ). This name must be globally unique and be protected. Others cannot use it to create an assembly with the same name. Generally, we use nested namespaces to meet this requirement. Using the name of a company, a project category (similar to a folder category), and other named project classes, you can avoid duplicate Assembly names to some extent. The use of the public/private key mechanism completely guarantees the uniqueness of the name. (For details about the confidentiality mechanism, see the special document. The following describes the application of sn.exe, a powerful name tool:

Generate public/private key pair files

. Sn.exe, a powerful name tool in the netstructure, helps you sign an assembly with a strong name. However, by signing an assembly with a strong name, you can ensure the global uniqueness of the name. The sn.exe tool provides options for key management, Signature generation, and signature verification. An important application of CMK is to generate a new key pair and write it to the specified file. The shared assembly that references this key pair file will ensure a unique name.

 

How to compile a CS as a module

 
CSC/Target: module hello. CS

How to add a module to a DLL

 
CSC/Target: Library/addmodule: A. netmodule/Out: B. dll

Example of dynamically loading and creating an assembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.