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

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

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

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. PHP中的变量名,函数名,类名是区分大小写的吗

    在PHP中,自定义的函数名,类名,以及内置的函数,关键字是不区分大小写的,比如: class,Class,CLASS,while,While,ECHO,echo,NULL,Null 都是一样的. 但是 ...

  2. 作业要求20181113-4 Beta阶段第1周/共2周 Scrum立会报告+燃尽图 02

    作业要求:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2384 版本控制:[https://git.coding.net/lglr201 ...

  3. 按照Right-BICEP要求设计四则运算3程序的单元测试用例

    按照Right-BICEP要求: Right——结果是否正确? B——是否所有的边界条件都是正确的? I——能查一下反响关联吗? C——能用其它手段交叉检查一下吗? E——你是否可以强制错误条件发生? ...

  4. python 动态获取当前运行的类名和函数名的方法

    一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...

  5. 本周WEB技术学习情况

    相较于之前本周有了明显的进步    之前不熟悉的知识点在多次的实机中得到巩固加深,用得越来越得心应手 我认为只要多用功更加自主的学习  web其实并不难 希望自己天天进步

  6. TCP系列44—拥塞控制—7、SACK关闭的快速恢复

    ) return;    delta = ssthresh - in_flight;     prr_delivered += newly_acked_sacked; if (delta < 0 ...

  7. QMultiMap使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QMultiMap使用     本文地址:http://techieliang.com/201 ...

  8. 【Leetcode】72 Edit Distance

    72. Edit Distance Given two words word1 and word2, find the minimum number of steps required to conv ...

  9. c# AOP 文章地址

    AOP:aspect oriented programing 面向切面编程.大概就是在程序的指定地方,可以做拦截然后插入执行指定的一段程序,这种模式在写日志,权限检查等操作很有用,这些操作都是固定的处 ...

  10. 【Linux笔记】CentOS yum 安装 vsftpd

    vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序.特点是小巧轻快,安全易用,下面直接上干货. 一.安装vsftp 以管理员的身份使用yum命令安装vsftp: [root@localh ...