首先这种情况出现在应用程序启动前的方法里面。

本想通过发射来实现一些功能。谁知道被这个坑了。

碰到这种问题。已经相当无语了。同时也不知道该如何解决。望有能之士帮忙解答

using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Compilation;
using System.Web.Hosting;
using Infrastructure; [assembly: PreApplicationStartMethod(typeof(PreApplicationInit), "InitializePlugins")]
namespace Infrastructure
{
public class PreApplicationInit
{
static PreApplicationInit()
{
var pluginsPath = HostingEnvironment.MapPath("~/plugins"); var pluginsTempPath = HostingEnvironment.MapPath("~/plugins/temp"); if (pluginsPath == null || pluginsTempPath == null)
throw new DirectoryNotFoundException("plugins"); PluginFolder = new DirectoryInfo(pluginsPath);
TempPluginFolder = new DirectoryInfo(pluginsTempPath);
} /// <summary>
/// The source plugin folder from which to copy from
/// </summary>
/// <remarks>
/// This folder can contain sub folders to organize plugin types
/// </remarks>
private static readonly DirectoryInfo PluginFolder; /// <summary>
/// The folder to copy the plugin DLLs to use for running the app
/// </summary>
private static readonly DirectoryInfo TempPluginFolder; /// <summary>
/// Initialize method that registers all plugins
/// </summary>
public static void InitializePlugins()
{
var assemblies = PluginFolder.GetFiles("*.dll", SearchOption.AllDirectories)
.Select(x => Assembly.LoadFrom(x.FullName)); foreach (var assembly in assemblies)
{
var type = assembly.GetTypes().FirstOrDefault(t => t.GetInterface(typeof(IModule).Name) != null);
if (type == null) continue;
//Add the plugin as a reference to the application
if (AppDomain.CurrentDomain.GetAssemblies().All(a => a.FullName != assembly.FullName))
{
BuildManager.AddReferencedAssembly(assembly);
} //Add the modules to the PluginManager to manage them later
var module = (IModule)Activator.CreateInstance(type);
PluginManager.Current.Modules.Add(module, assembly);
}
}
}
}

  上面是代码。

如果通过Type.IsAssignableFrom方法来查找接口的实现,根本查不到。

这是目录结构

这是Module的实现

using System;
using Infrastructure; namespace NewsPlugin
{
public class Module:IModule
{
public string Name {
get
{
return "NewsPlugin";
}
set
{
if (value == null) throw new ArgumentNullException("value");
this.Name = value;
}
}
}
}

.Net平台下实例类型无法转换成接口类型?的更多相关文章

  1. long类型字段转换成varchar2类型

    參考文档: How to Convert a Long to Varchar2 (文档 ID 228532.1) /*long类型字段转换成varchar2类型*/ --建表 create table ...

  2. mysql 查询 int类型日期转换成datetime类型

    数据库日期类型是int类型的,该查询结果是datetime类型的 SELECT from_unixtime( `时间列名` ) FROM 表名 如果原来类型是datetime类型,查询结果要是int类 ...

  3. js string类型时间转换成Date类型

    方法一: var t = "2015-03-16";var array =  t.split("-");var dt = new Date(array[0], ...

  4. MySQL如何把varchar类型字段转换成int类型进行倒叙排序

    SELECT * FROM sheet2 t1 WHERE t1.`金额`+'0' ORDER BY t1.`金额` DESC;

  5. Angular js 双向绑定时字符串的转换成 数字类型的问题

    问题: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <scrip ...

  6. JSON.stringify实例应用—将对象转换成JSON类型进行AJAX异步传值

    在上一篇中,对JSON.stringify()方法有了初步的认识,并且做了一些简单的例子.本篇将进一步将JSON.stringify用在复杂些的实例中,例如如下需求: 在进jQuery AJAX异步传 ...

  7. Swift - 将String类型的数字转换成数字类型

    Swift中,如果要把字符串转换成数字类型(比如整型,浮点型等).可以先转成NSString类型,让后再转. 1 2 3 4 //将文本框中的值转换成数字 var i = (tf1.text as N ...

  8. 工作随笔——Golang interface 转换成其他类型

    新的公司,新的氛围.一年了,打算写点什么.so,那就写google的golang语言吧. 最最最基础的语法结构见go语言菜鸟教程 接下来写点菜鸟教程没有的. go语言的设计者认为:go语言必须让程序员 ...

  9. python将字符串类型list转换成list

    python读取了一个list是字符串形式的'[11.23,23.34]',想转换成list类型: 方式一: import ast str_list = "[11.23,23.34]&quo ...

随机推荐

  1. gulp配置文件(gulpfile.js)

    需要安装的插件 "gulp": "^3.9.1","gulp-clean": "^0.3.2","gulp-c ...

  2. 用了这么多年的MCU,你知道哪些MCU原厂最牛?

    单片机诞生于1971年,经历了SCM.MCU.SoC三大阶段.单片机由以前的1位.4位.8位.16位,发展到现在的32位甚至64位. 90年代后随着消费电子产品大发展,单片机技术得到了巨大提高,相继诞 ...

  3. 使用C和C++实现“电梯”的区别

    C 面向过程:       该电梯不允许未卜先知,故程序需逐条处理乘客请求并更新当前各变量状态.       如何获得最短时间:是否立即响应请求,计算出不同决策下的总时间,并进行比较,然后选择最短时间 ...

  4. Spring1()

    目的: 降低Java开发的复杂性 使用策略: 基于POJO的轻量级和最小侵入式的编程 通过依赖注入和面向接口实现松耦合 基于切面和惯例进行声明式编程 通过切面和模版减少样式代码 依赖注入:由Sprin ...

  5. SQL 语句(增删改查)

    一.增:有4种方法1.使用insert插入单行数据: --语法:insert [into] <表名> [列名] values <列值> 例:insert into Strden ...

  6. 结对编程——paperOne基于java web的简易四则运算出题网站

    项目成员:张金生     张政 需求分析: 1.要进行四则运算: 2.运算题目随机: 3.进行对错判断: 4.整数运算. 程序概要: 1.用JSP实现: 2.用户可选择题目数量: 3.答题页用表格列出 ...

  7. Delphi 组件渐进开发浅谈(二)——双简合璧

    2.双简合璧2.1.带有T[x]Label的T[x]Edit组件 请允许我用[x]的书写方式来表示不同的对象.因为随后将大量提及TLabeledEdit与TTntLabeledEdit.TCustom ...

  8. 最大流Dinic算法模板(pascal)

    program rrr(input,output); const inf=; type pointer=^nodetype; nodetype=record t,c:longint; next,rev ...

  9. 【数据库_Postgresql】sql查询结果添加序号列

    ROW_NUMBER () OVER (ORDER BY A .ordernumber ASC) AS 序号

  10. Day 2 笔记 数据结构

    Day 2 笔记 数据结构 1.栈.队列.链表等数据结构都是线性数据结构 2.树状数据结构:二叉堆,线段树,树状数组,并查集,st表... 优先队列其实与二叉堆的存储方式并不相同. 一.二叉堆 1.二 ...