• 关于AppDomain 创建实例进行程序集之间的通讯问题


            各位高手们,我在用AppDomain 的CreateInstanceFromAndUnwrap 创建一个实例进行程序之间的通讯时,会抛异常,提示"Constructor on type 'DllResource.DeriveClass' not found.",代码如下:

    private BaseClass GetTrigger(string FileName)//返回指定文件的TriggerDesignerFacade
            {
                try
                {
                    AppDomainSetup info = new AppDomainSetup();

                    info.ApplicationName = "Load";

                    AllTriggersDomain = AppDomain.CreateDomain(FileName, null, info);

                    Domains.Add(FileName, AllTriggersDomain);

                    object[] parms = { FileName };

                    BindingFlags bindings = BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public;

                    //创建实践实现程序集之间的通讯
                    var Trigger = (BaseClass)AllTriggersDomain.CreateInstanceFromAndUnwrap(FileName,
                                                                "DllResource.DeriveClass", true, bindings, null, parms, null, null, null);

                    //Assembly aDll = Trigger.GetLoadAssembly(FileName);

                    //var rc = (BaseClass)aDll.CreateInstance("DllResource.DeriveClass");

                    //rc.SetSettingFolder(System.IO.Path.GetDirectoryName(FileName));

                    //return rc;

                    return null;
                }
                catch
                {
                    return null;
                }
            }

    我想调用抽象类进行通讯,可是创建实例时失败,在这里BaseClass 是基类(抽象类) DeriveClass 是继承类;

    我把这行代码改成:

                    var Trigger = (BaseClass)AllTriggersDomain.CreateInstanceFromAndUnwrap(FileName,
                                                                "DllResource.BaseClass", true, bindings, null, parms, null, null, null);

    也是一样提示:"Constructor on type 'DllResource.BaseClass' not found."  

    下面是我的继承类和基类的代码:

    继承类:

    namespace DllResource
    {
        class DeriveClass : BaseClass
        {
            public DeriveClass ()   
            {

            }

            public override void Display()
            {
                throw new NotImplementedException();
            }
            public override int Counter(int num)
            {
                return num++;
            }
           
        }
    }

    基础类: 

    namespace DllResource
    {
        public abstract class BaseClass
        {
          
            public abstract void Display();

            public abstract int Counter(int num);
        }
    }

    不知道怎么解决,请各位高手指点,在线等...................

     

  • 相关阅读:
    Mongodb 插入数据的方式
    vue插槽(slot)的模板与JSX写法
    vue-resource+iview上传文件取消上传
    封装全局icon组件 svg (仿造element-ui源码)
    vue 修改框架less变量
    vue webpack多页面构建
    vue2 自定义全局组件(Loading加载效果)
    制作npm插件vue-toast-m实例练习
    iview+axios实现文件取消上传
    CSS Variables
  • 原文地址:https://www.cnblogs.com/wangzhuangye/p/1338476.html
Copyright © 2020-2023  润新知