.netCore 反射 :Could not load file or assembly 系统找不到指定文件
“System.IO.FileNotFoundException:“Could not load file or assembly 'ClassLibrary2, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。””
在 .net 程序开发中我们会经常用到反射,最近在开始慢慢接触 .netCore。Core 反射的语法也是一样的,所以写下来也没有什么问题,但是一运行,就弹出了开头的 异常。
项目结构如下
ClassLibrary3 是一个接口
namespace ClassLibrary3
{
public interface IClass1
{
void Print();
}
}
ClassLibrary2 是 ClassLibrary3 的实现
namespace ClassLibrary2
{
public class Class1:IClass1
{
public void Print()
{
Console.WriteLine("Print.....");
}
}
}
主程序通过反射获取到到类型并创建对象
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!"); Assembly assembly = Assembly.Load(new AssemblyName("ClassLibrary2"));
Type type = assembly.GetType("ClassLibrary2.Class1");
var instance = (IClass1)Activator.CreateInstance(type);
instance.Print();
Console.ReadLine();
}
}
这代码都这里没有问题,但是执行的时候却抛出了 开篇的异常。仔细检查了下,ClassLibrary2 生成的 dll 确认已经是复制到了主程序目录下。
刚开始接触Core 也没有系统去熟悉,最后经过多方努力后,发现在主程序项目下有个 deps.json 的文件
文件内容是这样的(里面没有 ClassLibrary2 因为我们没有在项目中引用 ClassLibrary2)
然后想着 那异常提示找不到路径,那我们在这里配置下不久可以了?
然后改成如下:
这时候我们运行程序:
完美!
.netCore 反射 :Could not load file or assembly 系统找不到指定文件的更多相关文章
- Could not load file or assembly ‘ Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342’ or one of its dependencies系统找不到指定文件 处理方法
前些天做EF Model-First测试,开发环境为VS2013,数据库为Oracle 11g.所有东西都装好数据模型已经建立后准备执行“根据模型生成数据库”命令时,出现:Could not load ...
- 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: "file:///D:\testService"未能加载文件或程序集。系统找不到指定文件。
@echo.@if exist "%windir%\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe" goto INSTALL ...
- Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting'.系统找不到指定文件
项目部署到服务器后出现如下错误信息: Parser Error Message: Could not load file or assembly 'System.ServiceModel.Domain ...
- NET core 添加了新的nuget包,部署出现Could not load file or assembly
这个坑,今天整了一天,我添加了Microsoft.AspNetCore.Mvc.Versioning包,结果发布到服务器,我复制了dll过去出现了一直找不到加载不成功的问题 Startup.Confi ...
- 【C# 程序集】.NET core Could not load file or assembly
NET core 添加了新的nuget包,部署出现Could not load file or assembly 这个坑,今天整了一天,我添加了Microsoft.AspNetCore.Mvc.Ver ...
- configuration error-could not load file or assembly crystaldecisions.reportappserver.clientdoc
IIS启动网站后报错: configuration error Could not load file or assembly 'crystaldecisions.reportappserver.cl ...
- Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its de
页面加载时出现这个错误: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Cul ...
- ASP.NET corrupt assembly “Could not load file or assembly App_Web_*
以下是从overFlow 复制过来的问题 I've read through many of the other questions posted on the same issue, but I s ...
- Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0 系统找不到指定的文件。
环境: web服务器: ip:192.168.1.32 ,安装有 Visual Studio Premium 2013 操作系统: Microsoft Server 2008 r2+sp1 数据库服 ...
随机推荐
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
- .nettiers和SQLite搅合到一块之后遇到的问题
第一步 用SQLiteStudio生成一个新的数据库,sqlitetest,新建一张表test,建立一个主键字段ID,一个字符字段Name,建立完成,留待后用. 第二步 用VS2010建立一个sqli ...
- Feature分支
软件开发中,总有无穷无尽的新的功能要不断添加进来. 添加一个新功能时,你肯定不希望因为一些实验性质的代码,把主分支搞乱了,所以,每添加一个新功能,最好新建一个feature分支,在上面开发,完成后,合 ...
- chrome 浏览器插件开发(二)—— 通信 获取页面变量 编写chrome插件专用的库
在chrome插件的开发过程中,我遇到了一些问题,在网上找了不少文章,可能是浏览器升级的原因,有一些是有效的也有无效的.下面我简单的分享一下我遇到的坑,以及我把这些坑的解决方案整理而成的js库 —— ...
- 《JavaScript高级程序设计第三版》——细碎知识痛点整理(第六章)
面向对象的程序设计 对象是一组没有特定顺序的值6.1.1 属性类型ECMAScript中有两种属性:数据属性和访问器属性.1. 数据属性Configurable 表示能否通过delete删除属性从而重 ...
- Oracle 启动 停止JOB
转自:https://www.cnblogs.com/qianbing/p/6971633.html --查看job下次执行时间以及间隔时间 '; --启动job ); --停用job EXEC DB ...
- view的superview的变换
今天遇到一个奇怪的问题,一个view(称为subview)被加在了一个cell(superView1)上,然后创建了一个view(为superView2),将subview重新加在了superView ...
- docker镜像文件导入与导出 , 支持批量
1. 查看镜像id sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/calico/node v1.0.1 c70511a ...
- python__标准库 : 正则表达式(re)
re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回none. re.search 扫描整个字符串并返回第一个成功的匹配. 替换: re.sub(p ...
- form submit 的callback方法
参考:http://hayageek.com/jquery-ajax-form-submit/ form的submit方法返回数据处理. 普通的form: $("#ajaxform" ...