zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Ubuntu下快速建立跨多个平台的cocos2d-x项目
    转盘抽奖效果练习
    javascript网页弹出层练习
    PHP中Terminal提示不是内部或外部命令,也不是可运行的程序问题解决
    网页授权获取用户信息(自我总结)
    用easywechat开发微信支付功能以及红包接口调用注意事项
    微信公众平台开发步骤(包括自定义菜单、网页授权、分享功能)
    laravel-wechat 配置安装
    第1讲 html介绍 html运行原理
    总结学习方向
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1820412.html
Copyright © 2011-2022 走看看