DOTNET Assembly basic

Source: Internet
Author: User
Tags dotnet

DOTNET Assembly basic(A overall topic assemblies and the Global Assembly Cache can be found in msdn)

Assemblies have the following properties:

  1. Assemblies are implemented as. EXE or. DLL files.

  2. You can share an assembly between applications by placing it in the Global Assembly Cache.

  3. Assemblies must be strong-named before they can be placed in the Global Assembly Cache. For more information, see strong-named assemblies.

  4. Assemblies are only loaded into memory if they are required. When loading a assembly, its dependency assemblies specified by references will be loaded automatically (resource DLL loading follows the same rule ).

  5. You can programmatically obtain information about an assembly using reflection. For more information, see the topic reflection.

  6. If you want to load an Assembly only to inspect it, use a method such as reflectiononlyloadfrom.

  7. You can use two versions of the same assembly in a single application. For more information, see extern alias.

How to: Load assemblies into an application domain

Loading when required means implicit assembly loading. If you want to explicitly load a DOTNET assembly, there are using choices to do. The most suggested one is to use system. reflection. Assembly. Load.

There are several ways to load an assembly into an application domain. The recommended way is to useStatic(SharedIn Visual Basic) load method of the system. reflection. Assembly class. Other ways assemblies can be loaded include:

  1. The loadfrom method of the Assembly class loads an assembly given its file location. Loading assemblies with this method uses a different load context.

  2. The reflectiononlyload and reflectiononlyloadfrom Methods load an assembly into the reflection-only context. assemblies loaded into this context can be examined but not executed, allowing the examination of assemblies that target other platforms. see how to: Load assemblies into the reflection-only context.

Note

The reflection-only context is new in the. NET Framework Version 2.0.

  1. Methods such as createinstance and createinstanceandunwrap of the appdomain class can load assemblies into an application domain.

  2. The GetType method of the type class can load assemblies.

  3. The load method of the system. appdomain class can load assemblies, but is primarily used for com interoperability. it shoshould not be used to load assemblies into an application domain other than the application domain from which it is called.

Note

Starting with. net Framework Version 2.0, the runtime will not load an Assembly that was compiled with a version of. NET framework that has a higher version number than the currently loaded runtime. this applies to the combination of the major and minor components of the version number.

You can specify the way the just-in-time (JIT) compiled code from loaded assemblies is shared between application domains. For more information, see application domains and assemblies.

C ++ vs DOTNET

Both support implicit/explicit assembly loading:

  1. Implicit assembly loading. c ++ doesn't support loading resource DLL in that way, while C # supports.
  2. Explicit assembly loading. c ++ uses loadlibrary while C # mainly uses assembly. Load.

Global Assembly Cache (msdn link)

It's a machine-wide code cache where to store assemblies that intend to be shared between applications. DOTNET assemblies shoshould always be deployed there; and you can install your assemblies into GAC by gacutil.exe mainly. you can easily find steps to action on it in detail by Google.

 

Each computer where the Common Language Runtime is installed has a machine-wide code cache called the Global Assembly Cache. The Global Assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

You shoshould share assemblies by installing them into the Global Assembly Cache only when you need. as a general guideline, keep Assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. in addition, it is not necessary to install assemblies into the Global Assembly Cache to make them accessible to com InterOP or unmanaged code.

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.