• dotNet Assembly Basic


    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 many 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 use the static (Shared in 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.

    NoteNote

    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 should not be used to load assemblies into an application domain other than the application domain from which it is called.

    NoteNote

    Starting with the .NET Framework version 2.0, the runtime will not load an assembly that was compiled with a version of the .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 should 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 should share assemblies by installing them into the global assembly cache only when you need to. 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.

  • 相关阅读:
    三分钟学会.NET微服务之Polly
    redis设置密码和redis主从复制
    程序员工作之外,如何再赚一份工资?
    吞吐量(TPS)、QPS、并发数、响应时间(RT)概念
    TPS和QPS的区别和理解
    制定一套适合自己团队的GITflow标准化工作流
    UvaLive 6600 Spanning trees in a secure lock pattern 矩阵行列式
    从零開始学Xamarin.Forms(一) 概述
    Unity 之 C# 利用回调函数实现C++匿名函数
    hdu 4324 Triangle LOVE(拓扑判环)
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1820412.html
Copyright © 2020-2023  润新知