.Net平台下实例类型无法转换成接口类型?
首先这种情况出现在应用程序启动前的方法里面。
本想通过发射来实现一些功能。谁知道被这个坑了。
碰到这种问题。已经相当无语了。同时也不知道该如何解决。望有能之士帮忙解答
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平台下实例类型无法转换成接口类型?的更多相关文章
- long类型字段转换成varchar2类型
參考文档: How to Convert a Long to Varchar2 (文档 ID 228532.1) /*long类型字段转换成varchar2类型*/ --建表 create table ...
- mysql 查询 int类型日期转换成datetime类型
数据库日期类型是int类型的,该查询结果是datetime类型的 SELECT from_unixtime( `时间列名` ) FROM 表名 如果原来类型是datetime类型,查询结果要是int类 ...
- js string类型时间转换成Date类型
方法一: var t = "2015-03-16";var array = t.split("-");var dt = new Date(array[0], ...
- MySQL如何把varchar类型字段转换成int类型进行倒叙排序
SELECT * FROM sheet2 t1 WHERE t1.`金额`+'0' ORDER BY t1.`金额` DESC;
- Angular js 双向绑定时字符串的转换成 数字类型的问题
问题: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <scrip ...
- JSON.stringify实例应用—将对象转换成JSON类型进行AJAX异步传值
在上一篇中,对JSON.stringify()方法有了初步的认识,并且做了一些简单的例子.本篇将进一步将JSON.stringify用在复杂些的实例中,例如如下需求: 在进jQuery AJAX异步传 ...
- Swift - 将String类型的数字转换成数字类型
Swift中,如果要把字符串转换成数字类型(比如整型,浮点型等).可以先转成NSString类型,让后再转. 1 2 3 4 //将文本框中的值转换成数字 var i = (tf1.text as N ...
- 工作随笔——Golang interface 转换成其他类型
新的公司,新的氛围.一年了,打算写点什么.so,那就写google的golang语言吧. 最最最基础的语法结构见go语言菜鸟教程 接下来写点菜鸟教程没有的. go语言的设计者认为:go语言必须让程序员 ...
- python将字符串类型list转换成list
python读取了一个list是字符串形式的'[11.23,23.34]',想转换成list类型: 方式一: import ast str_list = "[11.23,23.34]&quo ...
随机推荐
- 作业2-MathExam V2.0
MathExam V2.0 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 20 50 • ...
- 在html中怎么格式化输出json字符串
#今天的项目用到,看俊哥找到,特此记录下来 步骤: 1.在html页面中输入下面的标签,必须是在pre标签内输出格式才会生效: <pre id="songReqJson"&g ...
- C#的lock语句
文章:lock 语句(C# 参考) 代码: using System; using System.Threading.Tasks; public class Account { private rea ...
- lintcode-382-三角形计数
382-三角形计数 给定一个整数数组,在该数组中,寻找三个数,分别代表三角形三条边的长度,问,可以寻找到多少组这样的三个数来组成三角形? 样例 例如,给定数组 S = {3,4,6,7},返回 3 其 ...
- Docker 安装与常用命令介绍
docker的镜像文件作用就是:提供container运行的文件系统层级关系(基于AUFS实现),所依赖的库文件.已经配置文件等等. 安装docker yum install -y docker 启动 ...
- spring-test与junit
1.添加依赖 spring-test junit spring-context(自动添加依赖其他所需的spring依赖包) 2.在class前添加以下注解,用于配置xml文件的位置 @RunWith( ...
- 【week11】回顾
一.回答五个问题 第一次阅读<构建之法>之后的五个问题: 1.关于敏捷,书中说了我理解的就是介绍了敏捷就是“没有既定的计划与文档,马上写代码,随时发牢骚”,但是开发也是需要有一定的流程的, ...
- 【beta】Scrum站立会议第4次....11.6
小组名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 时间: 12:00——12:30 地点:传媒西楼220室 本次对beta阶段的需求进行更新如下: ...
- [Google] 看雪论坛: 安卓碎片化的情况
2018年10月28日早间消息,谷歌方面发布了Android各版本的最新份额数据,截止到10月26日.即便是已经推出3个月了,Android 9 Pie系统的用户数仍旧没有超过0.1%,导致未出现在榜 ...
- Redis 备份数据的两种方式
既然是数据库,那就一定有数据备份方式了,而且 Redis 是内存形式的数据库,更需要数据备份了,要不然断电数据就全都丢失了. Redis 数据备份有两种方式: RDB(数据快照) AOF(记录操作日志 ...