.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 数据库服 ...
随机推荐
- mysql的慢查询实战+sql优化
背景:使用A电脑安装mysql,B电脑通过xshell方式连接,数据内容我都已经创建好,现在我已正常的进入到mysql中 步骤1:设置慢查询日志的超时时间,先查看日志存放路径查询慢日志的地址,因为有慢 ...
- 一个TCP的问题,所谓TCP面向连接的虚电路到底是怎么实现的?
http://www.cskaoyan.com/thread-23715-1-1.html 今天我又查阅了一些资料,发觉一个问题,TCP所谓的面向连接的特性以及建立虚电路,与网络层虚电路服务好像有着本 ...
- 解决SurfaceView调用setZOrderOnTop(true)遮挡其他控件的问题
SurfaceView遮挡其他控件的项目背景: 最近在做播放器项目,由于底层实现是用Surface和OpenGL切换渲染,所以在布局里面同时使用了GLSurfaceView和SurfaceView,同 ...
- 2018.8.2 Juint测试介绍及其命名的规范
JUnit - 测试框架 什么是 Junit 测试框架? JUnit 是一个回归测试框架,被开发者用于实施对应用程序的单元测试,加快程序编制速度,同时提高编码的质量.JUnit 测试框架能够轻松完成以 ...
- Java 截屏工具类
PrintScreenUtils.java package javax.utils; import java.awt.AWTException; import java.awt.Dimension; ...
- MAC下secureCRT无法保存密码的解决方法
在mac下新安装了secureCRT,取代系统自带的终端工具,主要是为了方便链接服务器.mac下面的secureCRT默认保存不上密码, 我们选择了保存密码后,下次登录还是提示密码错误,需要重新认证输 ...
- Yarn下分片和分块源代码分析
public class FileSplit extends InputSplit implements Writable { private Path file; private long star ...
- React后台管理系统-品类的增加、修改和查看
1.页面 2.品类列表展示 let listBody = this.state.list.map((category, index) => { return ( ...
- kubernetes基础架构及原理
kubernetes简称“k8s” 其中“8”代表的是“k”和“s”中间的8个字母. k8s是Google公司开发的Borg项目中独立出来的容器编排工具,然后将其捐献给CNCF这个组织,然后发扬光大. ...
- Python__for循环和列表生成式的区别
话不多,上例子 >>> L = [,,] >>> for i in range(len(L)): L[i] = L[i] + L[i-] print(L) #结果 ...