zoukankan      html  css  js  c++  java
  • 关于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);
        }
    }

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

     

  • 相关阅读:
    数组的完全随机排列算法
    css超出2行部分省略号...
    前端面试题精华总结
    在地址栏输入网址后页面是如何呈现的?
    document.write和innerHTML的区别
    js运算符单竖杠“|”与“||”的用法和作用介绍
    border:none与border:0的区别
    如何实现浏览器内多个标签页之间的通信?
    js 关键字 in 的使用方法
    msyql: navicat 连接时msyql遇到的问题
  • 原文地址:https://www.cnblogs.com/wangzhuangye/p/1338476.html
Copyright © 2011-2022 走看看