小编Wen*_*You的帖子

在appdomain中加载静态类

我在C#AppDomain遇到了一个大问题.

我需要在.dll文件中加载一个静态类并执行它的方法:

  1. 当我尝试加载它们时

    Assembly.LoadFrom("XXXXX") // (XXXXX is the full path of dll)
    
    Run Code Online (Sandbox Code Playgroud)

    .dll不会自动或以编程方式卸载.

  2. 当我尝试在AppDomain中加载它们时

    adapterDomain = AppDomain.CreateDomain("AdapterDomain");
    (a)adapterDomain.CreateInstanceFrom(this.AdapterFilePath, this.AdapterFullName);
    (b)adapterAssembly=adapterDomain.Load(AssemblyName.GetAssemblyName(this.AdapterFilePath));
    
    Run Code Online (Sandbox Code Playgroud)

    如果我使用方法(a),因为目标类是静态类,它不起作用.

    如果我使用方法(b),因为目标.dll与我的项目不是同一个目录,我将得到一个例外.

如何加载.dll和静态类,然后在使用后卸载.dll?

c# appdomain static-class

4
推荐指数
1
解决办法
3490
查看次数

标签 统计

appdomain ×1

c# ×1

static-class ×1